5. Current limitations
• Request location access on iPhone, not Apple Watch
• Not scrollable on map
• Not zoomable on map
• Not opening Apple's map app
• 5 annotations at maximum
6. Location service
var locationManager = CLLocationManager()
override init() {
super.init()
locationManager.delegate = self
if CLLocationManager.locationServicesEnabled() {
switch CLLocationManager.authorizationStatus() {
case .AuthorizedAlways, .AuthorizedWhenInUse:
locationManager.startUpdatingLocation()
}
}
}
func locationManager(manager: CLLocationManager!, didUpdateToLocation newLocation: CLLocation!,
fromLocation oldLocation: CLLocation!) {
}
7. Use Handoff in case it's not granted yet
override init() {
let type = "com.example.com"
let userInfo = ["actionID": 1]
self.updateUserActivity(type, userInfo: userInfo, webpageURL: nil)
}
9. Cache
Cache annotation images
let image = UIImage()
let device = WKInterfaceDevice.currentDevice()
device.addCachedImage(image, name: "annotation")
self.mapView.addAnnotation(CLLocationCoordinate2DMake(0.0, 0.0)
withImageNamed:"annotation"
centerOffset:CGPointZero)
10. Realm
Realm is a replacement for SQLite & Core Data. It can save you
thousands of lines of code & weeks of work, and lets you craft
amazing new user experiences.
12. Usage between iOS and WatchKit
// Get the shared directory for the application group
let id = "group.com.example.my-app"
let fileManager = NSFileManager.defaultManager()
let container = fileManager.containerURLForSecurityApplicationGroupIdentifier(id)
// Set the default realm path to a location in the shared container
let fileName = "defualt.realm"
if let realmURL = container?.URLByAppendingPathComponent(fileName) {
RLMRealm.setDefaultRealmPath(realmURL.path)
}
// Get location info
let restaurant = Restaurant.allObjects().firstObject() as! Restaurant
let coordinate = CLLocationCoordinate2DMake(restaurant.latitude, restaurant.longitude)
13. App review
We found that the usefulness of your Apple Watch app is limited
by the minimal features it includes. Specifically, your Apple Watch
app only launches out to Maps.
— From Apple