Presentation at UIKonf 2015 in Berlin http://www.uikonf.com
Practical WatchKitDevelopment@claushoefele
View Slide
Kleinanzeigen TransitHopper
WatchKitAppWatchKitExtensioniOS AppWatchKit App vs Extension
Interactive Notifications
class TripDetailInterfaceController: WKInterfaceController {@IBOutlet private weak var map: WKInterfaceMap!override func awakeWithContext(context: AnyObject?) {super.awakeWithContext(context)...}override func willActivate() {super.willActivate()...}}
map.addAnnotation(coordinate, withPinColor: .Red)let coordinateRegion =MKCoordinateRegionMakeWithDistance[...]map.setRegion(coordinateRegion)
Tables
Paging
Hides when loadingOff On
WatchKitAppWatchKitExtensionRequesting Data
WatchKitAppWatchKitExtensioniOS AppopenParentApplication()
private func callParentApp() {let userInfo = ["input": "data"]WKInterfaceController.openParentApplication(userInfo) { replyInfo, error inprintln("reply \(replyInfo)")}}func application(_:handleWatchKitExtensionRequest:reply:)Calling the Parent App
Handoff
User Location PermissionsWatchKitAppWatchKitExtensioniOS AppWhen In UseAlways
WatchKitExtensioniOS AppSharingData
let defaults = NSUserDefaults(suiteName: "group.com.claushoefele.T")!func updateObjectForKey(key: String, item: T) {let data = NSKeyedArchiver.archivedDataWithRootObject(item)defaults.setObject(data, forKey: key)}
WatchKitExtensioniOS AppSignalling
func sendDarwinNotification(identifier: String) {let darwinNotificationCenter = CFNotificationCenterGetDarwinNotifyCenter()CFNotificationCenterPostNotification(darwinNotificationCenter,identifier, nil, nil, 1);}CFNotificationCenterAddObserver
Data Sync
“A WatchKit appcomplements your iOS app;it does not replace it.”–Apple Watch HIG
“Anything that could showthe user a progressspinner (however briefly)is a failure on my part.”–David Smith
“[…] many of us — developers included — arestill figuring out how thisdevice fits into daily life […]”–M.G. Siegler
Practical WatchKitDevelopment@claushoefelehttp://slack.fiveminutewatchkit.com