watchkit tips and tricks - apple inc. · 2016. 7. 8. · data and communication networking...

123
© 2015 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. #WWDC15 WatchKit Tips and Tricks Optimizing Watch apps Jake Behrens watchOS Frameworks Evangelist App Frameworks Session 228

Upload: others

Post on 06-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

© 2015 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC15

WatchKit Tips and TricksOptimizing Watch apps

Jake Behrens watchOS Frameworks Evangelist

App Frameworks

Session 228

Page 2: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes
Page 3: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes
Page 4: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Agenda

Page 5: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Agenda

Data and communication

Page 6: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Agenda

Data and communicationInterface elements

Page 7: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Agenda

Data and communicationInterface elementsNotifications

Page 8: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Agenda

Data and communicationInterface elementsNotificationsGlances

Page 9: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and Communication

Page 10: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationNetworking

Page 11: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationNetworking

https request

Page 12: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationNetworking

https requestAsk for a

background task assertion

Page 13: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationNetworking

https requestAsk for a

background task assertion

Hold backgroundtask assertion until

request finishes

Page 14: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationNetworking

https requestAsk for a

background task assertion

Hold backgroundtask assertion until

request finishes

Default NSURLSession

Page 15: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationNetworking

Page 16: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationNetworking

Request a background task assertion

NSProcessInfo.processInfo().performExpiringActivityWithReason("networkReq") { expired in if !expired { // We have a background task assertion. } else { // No background task assertion was given or we’re out of time. } }

Page 17: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationNetworking

Request a background task assertionExecutes block when called• Block executes on an asynchronous queue

NSProcessInfo.processInfo().performExpiringActivityWithReason("networkReq") { expired in if !expired { // We have a background task assertion. } else { // No background task assertion was given or we’re out of time. } }

Page 18: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationNetworking

Page 19: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationNetworking

dispatch_semaphore

Page 20: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationNetworking

dispatch_semaphoredispatch_semaphore_wait pauses execution

Queue to pause: let time = dispatch_time(DISPATCH_TIME_NOW, Int64(30 * Double(NSEC_PER_SEC))) dispatch_semaphore_wait(semaphore, time)

Page 21: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationNetworking

dispatch_semaphoredispatch_semaphore_wait pauses executionSignaling the semaphore resumes execution

Queue to pause: let time = dispatch_time(DISPATCH_TIME_NOW, Int64(30 * Double(NSEC_PER_SEC))) dispatch_semaphore_wait(semaphore, time)

Other Queue: dispatch_semaphore_signal(semaphore)

Page 22: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Demo

Page 23: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationAcross processes

Page 24: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationAcross processes

openParentApplication(reply:)

Page 25: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationAcross processes

openParentApplication(reply:)application(handleWatchKitExtensionRequest:reply:)

Page 26: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationAcross processes

openParentApplication(reply:)application(handleWatchKitExtensionRequest:reply:)

• Begin a background task for asynchronous work

Page 27: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationAcross processes

openParentApplication(reply:)application(handleWatchKitExtensionRequest:reply:)

• Begin a background task for asynchronous work• Turn custom objects into NSData for reply

Page 28: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationDevice to device

Introducing Watch Connectivity Pacific Heights Thursday 11:00AM

Page 29: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationDevice to device

openParentApplication(reply:) is unavailable in watchOS 2

Introducing Watch Connectivity Pacific Heights Thursday 11:00AM

Page 30: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationDevice to device

openParentApplication(reply:) is unavailable in watchOS 2Use WatchConnectivity in watchOS 2

Introducing Watch Connectivity Pacific Heights Thursday 11:00AM

Page 31: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationDevice to device

openParentApplication(reply:) is unavailable in watchOS 2Use WatchConnectivity in watchOS 2

Introducing Watch Connectivity Pacific Heights Thursday 11:00AM

Page 32: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationShared data

Page 33: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationShared data

Make use of app groups in existing watchOS apps

Page 34: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationShared data

Make use of app groups in existing watchOS appsUse NSUserDefaults for state data, not model data

Page 35: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationShared data

Make use of app groups in existing watchOS appsUse NSUserDefaults for state data, not model dataThink of simplifying your model for watchOS

Page 36: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes
Page 37: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Event

Focus

Keyword

NewsItem

PhotoPhotoRepresentation

Room

Session

SessionAsset

SessionFavorite

SessionFeedback

SessionFilter

SessionInstance

Track

User

Page 38: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes
Page 39: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Sessions Favorites

Page 40: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes
Page 41: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes
Page 42: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes
Page 43: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationHandoff

Page 44: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationHandoff

updateUserActivity(userInfo:webpageURL:)

Page 45: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationHandoff

updateUserActivity(userInfo:webpageURL:)

System invalidates user activities automatically

Page 46: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Data and CommunicationHandoff

updateUserActivity(userInfo:webpageURL:)

System invalidates user activities automatically• You can manually invalidate user activities, if needed

Page 47: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 48: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes
Page 49: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes
Page 50: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 51: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Prioritize content loading

Page 52: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Prioritize content loading

Page 53: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Prioritize content loading• Use dispatch_async() in willActivate()

Page 54: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Prioritize content loading• Use dispatch_async() in willActivate()

Load fewer table cells up front

Page 55: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Prioritize content loading• Use dispatch_async() in willActivate()

Load fewer table cells up frontUpdate information that has changed

Page 56: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 57: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 58: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 59: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 60: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 61: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Use properly sized assets from your server/app

Page 62: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Use properly sized assets from your server/appOptimize images using setImageData()

Page 63: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Use properly sized assets from your server/appOptimize images using setImageData()Use asset catalogs

Page 64: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 65: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 66: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Apple Watch

Page 67: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Apple Watch

2x

Page 68: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Apple Watch

38 mm 2x

☆2x

Page 69: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Apple Watch

38 mm 2x

☆42 mm 2x

☆2x

Page 70: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 71: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 72: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 73: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 74: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Multiple animated images means more processing and rendering

Page 75: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Multiple animated images means more processing and renderingReduce size and FPS for animated images

Page 76: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Multiple animated images means more processing and renderingReduce size and FPS for animated imagesRun animated images in reverse

backgroundGroup.startAnimatingWithImagesInRange(NSRange(location: 0, length: 15), duration: -1, repeatCount: 0)

Page 77: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Layout and Animation Techniques for WatchKit Pacific Heights Thursday 10:00AM

Apple Watch Design Tips and Tricks Presidio Friday 3:30PM

Interface Elements

Page 78: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Layout and Animation Techniques for WatchKit Pacific Heights Thursday 10:00AM

Apple Watch Design Tips and Tricks Presidio Friday 3:30PM

Interface Elements

Animation API in watchOS 2

Page 79: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Layout and Animation Techniques for WatchKit Pacific Heights Thursday 10:00AM

Apple Watch Design Tips and Tricks Presidio Friday 3:30PM

Interface Elements

Animation API in watchOS 2• Similar to UIView animations

Page 80: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Layout and Animation Techniques for WatchKit Pacific Heights Thursday 10:00AM

Apple Watch Design Tips and Tricks Presidio Friday 3:30PM

Interface Elements

Animation API in watchOS 2• Similar to UIView animations• Animate height, width, alpha, insets, and more

Page 81: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Layout and Animation Techniques for WatchKit Pacific Heights Thursday 10:00AM

Apple Watch Design Tips and Tricks Presidio Friday 3:30PM

Interface Elements

Animation API in watchOS 2• Similar to UIView animations• Animate height, width, alpha, insets, and more

Page 82: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 83: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Page 84: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Interface Elements

Take users directly to voice dictation

presentTextInputControllerWithSuggestions(nil, allowedInputMode: .Plain, completion: { result in // Work with result })

Page 85: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Notifications

Page 86: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Notifications

{ "aps": { "alert": { "body": "This shows in the notification.", "title": "Short-Look Title" }, "category": "mainCategory", "sound": "default" } }

Page 87: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

{ "aps": { "alert": { "body": "This shows in the notification.", "title": "Short-Look Title" }, "category": "mainCategory", "sound": "default" } }

Notifications

Page 88: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

{ "aps": { "alert": { "body": "This shows in the notification.", "title": "Short-Look Title" }, "category": "mainCategory", "sound": "default" } }

Notifications

Page 89: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Notifications

Page 90: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Notifications

Page 91: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Notifications

{ "aps": { "alert": { "body": "This shows in the notification.", "title": "Short-Look Title" }, "category": "mainCategory", "sound": "default" } }

Page 92: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Notifications

{ "aps": { "alert": { "body": "This shows in the notification.", "title": "Short-Look Title" }, "category": "myCategory", "sound": "default" } }

Page 93: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Notifications

{ "aps": { "alert": { "body": "This shows in the notification.", "title": "Short-Look Title" }, "category": "myCategory", "sound": "default" } }

Page 94: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Notifications

{ "aps": { "alert": { "body": "This shows in the notification.", "title": "Short-Look Title" }, "category": "mainCategory", "sound": "default" } }

Page 95: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Notifications

let notification = UILocalNotification() notification.fireDate = futureNotificationFireDate notification.alertBody = "This shows in the notification." notification.alertTitle = "Short-Look Title" notification.category = "mainCategory" notification.soundName = UILocalNotificationDefaultSoundName

Page 96: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Notifications

Page 97: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Notifications

Page 98: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

Page 99: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

Page 100: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

Page 101: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

Page 102: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

Page 103: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

Page 104: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

Page 105: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

Page 106: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

willActivate()

Page 107: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

willActivate()

• Do full setup before willActivate() finishes

Page 108: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

willActivate()

• Do full setup before willActivate() finishes

Reload deliberately

Page 109: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

willActivate()

• Do full setup before willActivate() finishes

Reload deliberatelyLimit number of alternate layouts

Page 110: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

willActivate()

• Do full setup before willActivate() finishes

Reload deliberatelyLimit number of alternate layoutsUse WKInterfaceDate or absolute times/dates

Page 111: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

Page 112: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

Page 113: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

Page 114: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Glances

Page 115: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Summary

Page 116: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Summary

Optimize networking with NSURLSession

Page 117: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Summary

Optimize networking with NSURLSessionImprove layouts for performance

Page 118: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Summary

Optimize networking with NSURLSessionImprove layouts for performanceEnsure Glance always has content visible

Page 119: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Summary

Optimize networking with NSURLSessionImprove layouts for performanceEnsure Glance always has content visibleBecome familiar with watchOS 2

Page 120: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

More Information

Documentation and VideoswatchOS 2 Transition GuideWatchKit Programming Guidehttp://developer.apple.com/watchOS

Sample CodeListerWatchKit Cataloghttp://developer.apple.com/watchOS

Technical SupportApple Developer Forumshttp://developer.apple.com/forums

Developer Technical Supporthttp://developer.apple.com/support/technical

General InquiriesJake Behrens, watchOS Frameworks [email protected]

Page 121: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Related Sessions

Apple Watch Design Tips and Tricks Presidio Friday 3:30PM

Designing for Apple Watch Presidio Wednesday 4:30PM

Introducing WatchKit for watchOS 2 Presidio Tuesday 10:00AM

WatchKit In-Depth, Part 1 Pacific Heights Wednesday 9:00AM

WatchKit In-Depth, Part 2 Pacific Heights Wednesday 10:00AM

Building Watch Apps Pacific Heights Tuesday 4:30PM

App Extension Best Practices Presidio Thursday 4:30PM

Page 122: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes

Lab

WatchKit and ClockKit Complications Lab Frameworks Lab A Friday 1:30PM

Page 123: WatchKit Tips and Tricks - Apple Inc. · 2016. 7. 8. · Data and Communication Networking dispatch_semaphore dispatch_semaphore_wait pauses execution Signaling the semaphore resumes