10 things you should know about WatchKit before you submit

26
10 things you should know about WatchKit before you submit trippiece Inc. @kitasuke

Transcript of 10 things you should know about WatchKit before you submit

Page 1: 10 things you should know about WatchKit before you submit

10 things you should know about WatchKit

before you submittrippiece Inc.@kitasuke

Page 2: 10 things you should know about WatchKit before you submit

1. How to communicate and

share data

Page 3: 10 things you should know about WatchKit before you submit

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}

Page 4: 10 things you should know about WatchKit before you submit

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

Page 5: 10 things you should know about WatchKit before you submit

Darwin Notification CenterMMWormhole

Page 6: 10 things you should know about WatchKit before you submit

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];}];

Page 7: 10 things you should know about WatchKit before you submit

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

Page 8: 10 things you should know about WatchKit before you submit

2. Background task

Page 9: 10 things you should know about WatchKit before you submit

Make sure that you handle the reply in background taskAppDelegate.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]; });}

Page 10: 10 things you should know about WatchKit before you submit

3. Handoff

Page 11: 10 things you should know about WatchKit before you submit

Use handoff to open your containing iOS app to ask user to

allow any kinds of permission required for WatchKitWatchKit app → Containing iOS app

Page 12: 10 things you should know about WatchKit before you submit

4. Current location on map

Page 13: 10 things you should know about WatchKit before you submit

Use custom image for annotationMap can display no more than five annotations at a time

Page 14: 10 things you should know about WatchKit before you submit

5. Group

Page 15: 10 things you should know about WatchKit before you submit

Use group to handle your UI

Page 16: 10 things you should know about WatchKit before you submit

6. Notifications

Page 17: 10 things you should know about WatchKit before you submit

3 steps1. Got sound and vibration

2. Look at your Apple Watch

3. Keep looking (Optional)

Page 18: 10 things you should know about WatchKit before you submit

7. Bundle nameVS

Bundle display name

Page 19: 10 things you should know about WatchKit before you submit

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...

Page 20: 10 things you should know about WatchKit before you submit

8. App icons for image assets

Page 21: 10 things you should know about WatchKit before you submit

Do not set same asset name for containing iOS app and WatchKit

app

Page 22: 10 things you should know about WatchKit before you submit

9. Xcode 6.2VS

Xcode 6.3

Page 23: 10 things you should know about WatchKit before you submit

A huge differenceXcode 6.2    Xcode 6.3

Page 24: 10 things you should know about WatchKit before you submit

10. Realm

Page 25: 10 things you should know about WatchKit before you submit

WatchKit & RealmBest combination ever!

What's Realm?

Tutorial: Sharing Data between WatchKit & your App, with Realm

Page 26: 10 things you should know about WatchKit before you submit

Any questions?