Ad

How To Know When The User Has Started An Apple Watch App?

- 1 answer

I would like to know when the user starts my Apple Watch app (started from menu or from complication). WKInterfaceController's documentation states that the didAppear method is called when the interface controller content is on screen.

In my simple example project I'm logging all calls to the didAppear method, and I see that it gets called also when the app is not visible on screen.

override func didAppear() {
   super.didAppear()
   log("didAppear") // Triggered when app not visible
}

My guess is that this has to do with snapshot refreshing, but is there any way to know when the user (not the system) has started my app?

Ad

Answer

Use applicationDidBecomeActive for this.

From Apple Developer Documentation:

WatchKit calls this method to let you know that your app transitioned from the inactive to the active state. Use this method to start any tasks that were paused or not yet started while the app was inactive.

Ad
source: stackoverflow.com
Ad