There are two subclasses of WKInterfaceController
in my Apple Watch app.
The first one is the entrance of another one, their relationships is nextPage
with the Interface Builder.
For the awakeWithContext
, willActivate
and didDeactivate
method in each InterfaceController, I printed them all out while watch app launching.
And I got this output:
awakeWithcontext -> First
awakeWithContext -> Second
willActivate -> First
willActivate -> Second
didDeactivate -> Second
and I swipe to the next InterfaceController:
willActivate -> Second
didDeactivate -> First
So now the question is:
Will all the awakeWithContext
method of all InterfaceControllers in Watch App be fired as long as launched?
What about the willActivate
method?
The life cycle of watchOS apps is as described below.
awakeWithContext
When initializing the page, awakeWithContext
will be called. This is the first method to be called, and no UI is displayed yet.
You should do something like updating model arrays for table views, setting properties, etc in awakeWithContext
. This method has a very similar job to initializers in simple classes (init()
), but this time in WKInterfaceController
s.
The answer of your first question:
awakeWithContext
will be called on ALL PAGES as soon as the watchOS app launches.
willActivate
When the interface controller is about to be displayed, willActivate
will be called.
You should update label values, actions and anything else related to view elements there.
The answer of your second question:
willActivate
will be called on ALL PAGES as soon as the watchOS app launches, but in contrast withawakeWithContext
, this will be called again as soon as you view the controller (in other words, when you navigate to that desired interface).
For the first time you launch the app, all controllers' didDeactivate
will be called, except the current, and when going to another, its willActivate
will be called prior to didDeactivate
being called on first one.
So the life cycle is:
1- awakeWithContext
of all views
2- willActivate
of all views
3- didDeactivate
of all views, except the first one (the current one)
And when swiping to the second:
1- willActivate
of the second view
2- didDeactivate
of the first view
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With