10 things you should know about WatchKit before you submit

  • View
    2.991

  • Download
    1

  • Category

    Software

Preview:

Citation preview

10 things you should know about WatchKit

before you submittrippiece Inc.@kitasuke

1. How to communicate and

share data

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}

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

Darwin Notification CenterMMWormhole

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

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

2. Background task

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

3. Handoff

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

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

4. Current location on map

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

5. Group

Use group to handle your UI

6. Notifications

3 steps1. Got sound and vibration

2. Look at your Apple Watch

3. Keep looking (Optional)

7. Bundle nameVS

Bundle display name

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

8. App icons for image assets

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

app

9. Xcode 6.2VS

Xcode 6.3

A huge differenceXcode 6.2    Xcode 6.3

10. Realm

WatchKit & RealmBest combination ever!

What's Realm?

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

Any questions?

Recommended