When to call the activation function () on a WCSession object

I wonder at what point activSession () could be called on a WCSession object on a watch and on an iOS device.

The documentation says:

Always assign a delegate and activate a session before invoking any session-related methods. The session must be configured and activated before sending messages or receiving information about the status of the connection.

At first, I decided that my code would initialize the session:

 if (WCSession.isSupported()) {
        session = WCSession.defaultSession()
        session.delegate = self
        session.activateSession()
    }

in viewDidLoad on the iOS device and willActivate on the sentinel side.

This works ... but I don't think this is a good solution. I am not very familiar with the life cycle of the application, but as I understand it, they are called every time the application is open.

" " ?

?

+4
1

WCSession viewDidLoad willActivate, , , , . .

application:didFinishLaunchingWithOptions AppDelegate applicationDidFinishLaunching ExtensionDelegate

, @NatashaTheRobot.

, , .

ccjensen , Complication, Notification strong > Glance, ExtensionDelegate init. applicationDidFinishLaunching .

+10

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


All Articles