What is the life cycle of the Watch app?

There are two subclasses of WKInterfaceController Apple Watch WKInterfaceController . The first is entering another, their nextPage relationship using Interface Builder. For the awakeWithContext , willActivate and didDeactivate in each ControlController interface, I printed them all when I started the application for viewing.

And I got this conclusion:

 awakeWithcontext -> First awakeWithContext ๏ผ> Second willActivate ๏ผ> First willActivate -> Second didDeactivate ๏ผ> Second 

and I will move on to the following InterfaceController:

 willActivate -> Second didDeactivate ๏ผ> First 

So now the question is:

Will the entire awakeWithContext method of all the interface controllers in the Watch application be launched, if they are running?

What about the willActivate method?

+5
source share
2 answers

The life cycle of watchOS applications is described below.

awakeWithContext

When the page is initialized, awakeWithContext is awakeWithContext . This is the first method to be called, and until the UI is displayed.

You should do something like updating model arrays to present tables, set properties, etc. in awakeWithContext . This method has very similar work with initializers in simple classes ( init() ), but this time in WKInterfaceController s.

The answer to your first question:

awakeWithContext will be called on ALL PAGES as soon as watchOS applications are launched.

willActivate

When the interface controller is displayed, willActivate will be called.

You must update the values โ€‹โ€‹of labels, actions, and everything related to the elements of the view.

The answer to the second question:

willActivate will be called on ALL PAGES as soon as the watchOS application but unlike awakeWithContext , it will be called again as soon as you see the controller (in other words, when you go to this desired interface).

The first time you run the application, all โ€œ didDeactivate controllers except the current willActivate will be called, and when you switch to another, it willActivate will be called before willActivate is called on the first.

So the life cycle:

1- awakeWithContext all views

2- willActivate all views

3- didDeactivate all views except the first (current)

And when scrolling to the second:

1- willActivate second view

2- didDeactivate first view

+5
source

awakeWithContext is called upon initialization. This method will be called on all of your pages in the watch application at startup.

willActivate is called when the interface controller is to be displayed. The reason the second willActivate interface controller is willActivate , followed by didDeactivate , is because this is the next page that may be on the screen. This happens to help load the next interface controller with the relevant data, since it will appear on the screen soon.

Therefore, if you had a 3rd page interface controller, its willActivate , followed by didDeactivate , is called when the 2nd interface controller is on the screen.

Apple Doc on willActivate . Navigating the pages on the watch may not explicitly say this, but they always help to read.

0
source

Source: https://habr.com/ru/post/1243831/


All Articles