Adding Lifecycle Methods

The lifecycle methods of WKExtensionDelegate and UIApplication (on iOS) protocols are similar, though they are fewer. The most common one to implement is applicationDidFinishLaunching, allowing you to do setup when the app is launched. The other two have you covered when the app is interrupted—for example, if the user gets a call in the middle of a run. First, applicationWillResignActive will be called on your delegate, allowing you to save your work, and then applicationDidBecomeActive lets you restore it once the app is back in the foreground.

The WatchKit extension lifecycle methods are shown here in the context of launching a WatchKit app. You see the state of the app from before it’s launched to when it’s running ...

Get Developing for Apple Watch, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.