WCSession not working with glances

Hello all,


Im trying to use watch connectivity with Messaging to retrieve data from the phone for my glance as well as my app (interface). The interface controller seems to be working. However for the GlanceInterface WCSession never is "reachable" thus not allowing me to use messaging to retrieve data. Do we need to start a WCSession in both the Glance and the interface? or just one maybe in the extensiondelegate.h. If we do need to start a session in the glance and interface has anyone run into the issue where it never is reacable in the glance?


I noticed is reachable is only true when the watch app is in the foreground. Does anyone have suggestions when the app is started to call messaging, it seems if I try to make the call right in the "willactivate" it will return an "device not reachable" error, but I dont want the users to have to push a button to load data , i want it loaded when the app is started.


Any suggestions or ideas would be great !


In glance and interface

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

Replies

yup im now able to achieve reachability with glances, so thats good. ELRaymond, do you have the necessary WCSession start in the glance also?

I take it back a little bit it seems to work very infrequently ... maybe it will be more consistent on a device..

it seems like i can get it to work once, but after that doesnt obtain reachability again.

I'm seeing the same behavior. Glances are very flakey. I’ve noticed the watch extension fails to communicate with the phone when the Glance fails. If I don’t use the Glance the watch and the phone simulators work just fine together. I’ve only been able to successfully get the glance to work 2 times in 2 hours. When it worked everything worked. It as a woohoo moment. I’m having difficulty trying to reproduce a successful Glance. What’s funny is I'm getting a sessionReachablilityDidChange toggling 0 to 1 as the Glance slides on and off everytime. So something happening?


Bummer

Sounds like things have improved for some a bit, but for those of you still having problems please help us by filing a bug report so that we can make sure these issues get fixed!

Hello Kaj,


Im seeing the same as you where the sessiondidchange is firing after you leave the glance and reachability is true when your leaving... I really think this is a simulator issue, i mean we'll know for sure next week. For now though i have consistently been able to get it to work, but not in a way it should be working. What i do is i start debug on glance and it works first time only (when simulator is not already running). So after that its never reachable. I open the main watch app, reachability is 100% working, hit Home after main app opens to "close" it, then the glance reachability works as it should. Again its flakey like you said and it REALLY should work 100% of the time.. but yeah..

My Bug number is :

22644129


Thanks Viking!

I think I have it working consistently in one direction! But far from ideal. When I have the Glance up in the simulator then go to the phone app and press my button. The Glance does update telling me the phone side is sending the Session to this guy:


(void) session:(nonnull WCSession *)session didReceiveApplicationContext:(nonnull NSDictionary<NSString *,id> *)applicationContext


It works every time. Yes your debug method does work for me but only once. As I see it, Apple just needs to get the communication going from the Glance to the phone working as the reply back to the watch is indeed working for me.

Even I ahve the same problem. In Glances, not able to communicate to ios App with WCSession. We can create the instances but, we will not be able to receive any callbacks in ios App.

I'm not sure if this is related or not, but the glance controller and the main interface controller are running in the same process. If each calls ```[WCSession defaultSession].delegate = self``` then they're potentially stealing the WCSession delegate away from one another. Whichever one doesn't have the delegate will appear to not get any messages through WatchConnectivity.

i am having the same issue... Automigrated my watchos1 to watchos2 after installing xcode 7 and exchanging the whole protocol handshake with wcsession.


its kind of sad that in watchos2 there is no backwards comp API call saying deprecated but still workiNg. Feel kind of stucked because i dont want to update my watch to public beta watchos2 just to test if glances commnication are working without simulator.


i Guess i have to create a copy of the app just to make it workiing with watchos1 and ios9 with xcode 7. hope th at this bug is fixed soon. Xcode is very unstable and having using my Mac

Any news about this problem?

Now watchOS 2 has been released and I have this issue also in the real Apple Watch, not only in the simulator.


I cannot understand if it is a problem of my app or a bug... In the documentation it seems that I have to include this in both the glance and interface:

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

The glance works properly when I reboot the Apple Watch and I open immediately the glance, but as I open my app, the glance doesn't work anymore!

Where else in your app are you setting `session.delegate = self;` ? There's only one shared WCSession object and it has only one delegate, so setting it elsewhere will effectively unset it everywhere else.

I am setting it also in the interface controller of my app.

I'll try to figure out a way to share it...

Here is my solution: I set the WCSession delegate only in the WKExtensionDelegate:

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


Now the app works fine in all situations, but the glance, if the app is not in background, will not have the session reachable... to have the glance working I have to launch the app and then open the glance! Any other suggestion?