Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Watchkit Communication

Watchkit Communication

Video of the talk is available at https://vimeo.com/119606531

The Watchkit architecture makes for some interesting challenges regarding getting data out of your main app and onto the watch. This covers the architectural and lifecycle basics before diving into the methods we have available to move data around to the watch.

Curtis Herbert

February 12, 2015
Tweet

More Decks by Curtis Herbert

Other Decks in Technology

Transcript

  1. What can we do in early 2015? Glance Notification App

    https://developer.apple.com/watchkit/
  2. What can we do in early 2015? Glance Notification App

    https://developer.apple.com/watchkit/ You can provide users with timely read-only information that they care about with a Glance — a quick and lightweight view of your app.
  3. What can we do in early 2015? Glance Notification App

    https://developer.apple.com/watchkit/ Actionable notifications built and designed with WatchKit let users take action right from their wrists.
  4. What can we do in early 2015? Glance Notification App

    https://developer.apple.com/watchkit/ Your app on Apple Watch contains a full user interface. Users can launch, control, and interact with your app in ways unique to Apple Watch.
  5. Watchkit app made of 2 parts - “App” and extension

    Extension <-> watch app is a lightweight channel Extension <-> parent app can only be started by the extension Architectural Takeaways
  6. E Watch Extension Initial Launch Watch “App” User launches app

    Load storyboard init awakeWithContext: Show UI willActivate
  7. Stay lightweight in watch extension, especially init and awake UI

    updates when screen isn’t active are dropped on the floor Lifecycle Takeaways
  8. [WKInterfaceController openParentApplication:@{...} reply:^(NSDictionary *replyInfo, NSError *error) { if (error) {

    NSLog(@"Error from parent: %@", error); } else { //do something with the reply info.... } }]; E Any WKInterfaceController
  9. openParentApplication:reply: • Will launch your parent app! • Great way

    to send actions / triggers Pros • Can’t do too many back-to-back (serialized queue) • Launches parent in background mode-only • Have fun with your app lifecycle Cons
  10. Parent App E iOS 8 Extension Extension data sharing ex:

    “com.consumedbycode.slopes.group” App groups x
  11. Parent App E iOS 8 Extension Extension data sharing ex:

    “com.consumedbycode.slopes.group” App groups x
  12. Parent App E iOS 8 Extension Extension data sharing ex:

    “com.consumedbycode.slopes.group” App groups x
  13. Core Data • Reuse existing model • Set up for

    multi-threading • KVO Pros • Core Data (I kid, I kid) • Bad place to store one-off values to pass around • Need to move DB to App Group container Cons
  14. Anywhere //get the current value NSNumber *currentSpeed = [wormhole messageWithIdentifier:@"currentSpeed"];

    //...or subscribe for updates [wormhole listenForMessageWithIdentifier:@"currentSpeed" listener:^(id messageObject) { //do something with the speed }]; E
  15. WKInterfaceController - (void)willActivate { [super willActivate]; [self.wormhole listenForMessageWithIdentifier:@"currentSpeed" listener:^(id messageObject)

    { //do something with the speed, update a label, etc }]; } - (void)didDeactivate { [super didDeactivate]; [self.wormhole stopListeningForMessageWithIdentifier:@"currentSpeed"]; } E
  16. MMWormhole • KVO • Great for one-off values Pros •

    Separate data you have to keep in sync from your model layer Cons
  17. openParentApplication:reply: great for actions, bad for lots of data fetching

    NSUserDefaults: great for data, but no notification of changes CoreData: great for sharing existing model data, bad for one-off messages Darwin Notification Center: consider in place of NSUserDefaults Communication Takeaways