Performing Tasks in Your iPhone App
The most common situation you’ll run into in WatchKit where you need to involve the parent app is performing a task that you can’t perform on the watch. Perhaps you need to make a network connection; perform computationally intensive image rendering that would take much longer than the watch app will be active; or access a system framework that’s unavailable from WatchKit, such as HealthKit. WKInterfaceController has a class method built exactly for these needs: openParentApplication(_:reply:). Pass in a Dictionary and a closure to be executed when the task is done, and your iPhone app takes over. Let’s implement this in the TapALap app to save workout data to HealthKit.
Get Developing for Apple Watch now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.