10 things you should know about WatchKit before you submit

4,843 views

Published on

Potatotips 15/4/2015

Published in: Software, Engineering

10 things you should know about WatchKit before you submit

  1. 1. 10 things you should know about WatchKit before you submit trippiece Inc. @kitasuke
  2. 2. 1. How to communicate and share data
  3. 3. openParentApplication:reply: InterfaceController.m [WKInterfaceController openParentApplication:@{@"action": @"count"} reply:^(NSDictionary *replyInfo, NSError *error)] { if (error) { // error } else { // do something } }]; application:handleWatchKitExtensionRequest:reply: AppDelegate.m - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply { // do something }
  4. 4. Pros - Can let your containing iOS app execute some tasks in the background - Doesn't matter whether your containing iOS app is currently running or not Cons - If you call multiple times in quick succession, each subsequent call is delayed - Should always be triggered by your WatchKit app
  5. 5. Darwin Notification Center MMWormhole
  6. 6. self.wormhole = [[MMWormhole alloc] initWithApplicationGroupIdentifier:@"group.com.mutualmobile.wormhole" optionalDirectory:@"wormhole"]; [self.wormhole passMessageObject:@{@"buttonNumber" : @(1)} identifier:@"button"]; [self.wormhole listenForMessageWithIdentifier:@"button" listener:^(id messageObject) { self.numberLabel.text = [messageObject[@"buttonNumber"] stringValue]; }];
  7. 7. Pros - Simple and fast - Can be used for other extensions, not only WatchKit Cons - WatchKit app should be awake to receive immediately - Keep sending message to WatchKit app to always show the right data
  8. 8. 2. Background task
  9. 9. Make sure that you handle the reply in background task AppDelegate.m - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply { __block UIBackgroundTaskIdentifier watchKitHandler; watchKitHandler = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"backgroundTask" expirationHandler:^{ watchKitHandler = UIBackgroundTaskInvalid; }]; reply(nil) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)NSEC_PER_SEC * 1), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{ [[UIApplication sharedApplication] endBackgroundTask: watchKitHandler]; }); }
  10. 10. 3. Handoff
  11. 11. Use handoff to open your containing iOS app to ask user to allow any kinds of permission required for WatchKit WatchKit app → Containing iOS app
  12. 12. 4. Current location on map
  13. 13. Use custom image for annotation Map can display no more than five annotations at a time
  14. 14. 5. Group
  15. 15. Use group to handle your UI
  16. 16. 6. Notifications
  17. 17. 3 steps 1. Got sound and vibration 2. Look at your Apple Watch 3. Keep looking (Optional)
  18. 18. 7. Bundle name VS Bundle display name
  19. 19. Containing iOS app's Bundle name is for app name in companion app WatchKit Extension's Bundle display name is for sash name It's weird, so might be changed in the future...
  20. 20. 8. App icons for image assets
  21. 21. Do not set same asset name for containing iOS app and WatchKit app
  22. 22. 9. Xcode 6.2 VS Xcode 6.3
  23. 23. A huge difference Xcode 6.2    Xcode 6.3
  24. 24. 10. Realm
  25. 25. WatchKit & Realm Best combination ever! What's Realm? Tutorial: Sharing Data between WatchKit & your App, with Realm
  26. 26. Any questions?

×