WatchKit In-Depth Part 1 (207)
- Application - WKInterfaceController
- Glance - WKInterfaceController
- Notification - WKUserNotificationInterfaceController
- Complication - CLKComplicationDataSource WKInterfaceController Interface properties Menu handling
Document folder - Non-purgeable - Not restored Caches folder - Purgeable
Interface.storyboard, edited in interface builder. Same as watchOS 1 with some new elements
setImageNamed defaults to images in application rather than extension
Application is responsible for playing media file, recording audio files. Extension is responsible for downloading media and uploading/processing recorded audio files.
You need to use a shared application group to share data betwen extension and app.
NSURLSession allows for background downloads/uploads to http/https, downloaded files must be copied before the system purges the temporary cache
- Share data (iOS <> watchOS)
- transfer files (iOS <> watchOS)
- Make requests to iPhone app from extension
WatchKit extensions on watchOS 1 targets the iOS Platform/SDK, share code with iPhone application and cache images, respond to openParentApplication() requests which are fast since its phone to phone
In watchOS 2 there is a new platform and SDK dedicated to watchOS. Subset of iOS frameworks are available, can include project frameworks (but will be shipped to watch)
“Same API with some changes and additions”
Create a new watchOS target and pull in code that can be reused.
Same interface/glance/notification controllers, replace WKImageCacheing with UIImage and openParentApplication with WatchConnectivity
watchOS version of UIApplicationDelegate
Only tracks the
applicationDidFinishLaunching()
called once on launch, application is not yet active
applicationDidBecomeActive()
each time app becomes visually active, activate timers/update state that changed while app was in background/killed
applicationWillResignActive()
only call before going to background, cancel/pause timers, save state, prepare to be inactive
handleUserActivity()
will be called when glance is used or when a complication is tapped. This will now be called on the WKExtension delegate rather than root interface controller
Property will be added in future seed, current state:
let rootController = WKExtension.sharedExtension.rootInterfaceController
rootController.popToRoot…()
rootController.prepForUserActivity()
openSystemURL
handles tel://
sms://
or other system supplied url schemes
didReceiveRemoteNotification()
didReceiveLocalNotifiaction
need to call completion in timely manner
Local notifications can only be scheduled on the phone, will follow the normal routing rules (phone in sleep/active, etc…)
If you specify notification actions as having a text reply then the watch will display text input interface controller if the user hits reply, can provide suggestions in watchOS app
didReceiveRemoteNotification
will be called similar to iOS you need to provide UI when app is active
- .Alert
- .SideBySide
- .ActionSheet