WCSession interface in Glance (Watch OS 2.0)

I am trying to use messaging (part of the new WatchConnectivity introduced in watchOS 2.0) in my opinion. In my opinion, the controller has it.

-(void)willActivate { [super willActivate]; if ([WCSession isSupported]) { WCSession *session = [WCSession defaultSession]; session.delegate = self; [session activateSession]; } } 

This works in the main interface, although it only takes a few seconds to become available in the simulator. I control accessibility by checking sessionReachabilityDidChange: However, only in my opinion the interface never becomes accessible. Without reaching the goal, I can not get data from the phone. Has anyone come across this? Perhaps this is just a simulator problem. I am using xCode 7 Beta 5.

Thanks!

+4
source share
2 answers

There is only one shared WCSession object, and it has only one delegate, so installing it twice in app init / willActivate and then in Glance init / willActivate will cause problems.

A viable way is to set it in the WKExtensionDelegate initialization method

 class ExtensionDelegate: WKExtensionDelegate, WCSessionDelegate{ let TAG : String = "ExtensionDelegate: " let session = WCSession.defaultSession() override init () { super.init() println("\(TAG) - init") println("\(TAG)Setting delegate and Activating WCSession.defaultSession()...") session.delegate = self session.activateSession() } . . . } 
+2
source

Before your session becomes available, you can contact updateApplicationContext:

So, you can check on the iOS side that the watch is available, and if not, then use updateApplicationContext: to set some application context data that will be available for viewing when the user starts using your watch application. Or even at first glance, you can use this contextual data.

When your willActivate method is called, you can set up a WCSession delegate and activate the session. When the session is activated, it will call your session: didReceiveApplicationContext: callback with previously set appcontext data. After that, you can use sendMessage, because at that moment your watch is available. Note that the updateApplicationContext method is not called on the main thread.

In the other direction, you can wake an iOS application in the background using the sendMessage method from the clock. This means that you need to configure WCSession in your appdelegate on the iOS side.

Achievable state requires both the iOS app and the watch app (or look) to run.

Check out the WWDC 713 session for more information: Introducing Watch Connectivity

+1
source

All Articles