Watch Connectivity - WCSessionDelegate methods not called (simulator)

I have setup WCSessions in both the appDelegate in the iOS app and in my InterfaceController and I am attempting to use sendMessage(_:replyHandler:errorHandler:) in the InterfaceController to send a message to the iOS app and receive a reply in the simulator.


After connecting to both targets for debugging my breakpoint for sendMessage(_:replyHandler:errorHandler:) on the watch is hit but the subsequent call to didReceiveMessage(_:replyHandler) in the iOS app is not called. The error handler is not called either. The WCSessions should both be activated and the delegates are set as well (I have both apps open and in the foreground). The boolean value for session.reachable is true before attempting to call sendMessage(_:replyHandler:errorHandler:)


Is there something else I am missing?


If need be, I can post the code in question.

Hi,


The code would be helpful in making sure the setup all looks correct. Please make sure to include the set up of WCSession as well as the communication API calls. Sounds like you have the basics down though!

I'm having exatly the same problem, but with an actual Watch and iPhone (ie not simulator).


Interestingly, the Apple sample code for WCSession, Potloc, had the same problem in a beta and/or Xcode version, then worked OK in another, and now fails to complie under the latest Xcode beta. Unfortunately I have two development environments that have had different versions of Xcode and OS X at various times combined with the iOS 9 and OS2 betas, so I haven't kept track of what version of Potloc worked in which specific environment.


This is very frustrating.


Regards,


Michael

If you believe you are hitting a bug, the best way for us to help you is if you file a bug, include a sample project and instructions for how to reproduce and report back here with the radar number. I'll make sure they get routed to the right engineers!

I'm seeing this in both simulator and device as of beta 5 for both sendMessage and transferFile. Has anyone been able to make this work?

I am struggling with this on the sumulator too. Here's what sorta seems to be working for me, today, with the main app. Haven't found a way to get notifications to work yet.


1. Build the main project first to install on the phone simulator. Don't kill

2. Switch schemes and build your watch 2.0 app to install and run on the watch simulator.

3. Click your installed ios app in the phone simulator.



The watch sender:

--------------------------


NSDictionary* message = dictionary of stuff to send

[[WCSession defaultSession] sendMessage:message

replyHandler:^(NSDictionary *replyInfo) {

NSLog(@"replyInfo: %@",replyInfo);

// do stuff with the reply

}


errorHandler:^(NSError *error) {

NSLog(@"Watch error while sending message: %@",error);

}

];


The ios app receiver (In order to get the reply handler to work, at least it seems to, I moved it to another thread):

----------------------------


- (void)session:(WCSession *)mySession didReceiveMessage:(NSDictionary<NSString *,id> *)message

replyHandler:(void (^ )(NSDictionary<NSString *, id> * replyMessage))replyHandler{


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

// do stuff

// more stuff

NSDictionary* returnInfo = info to return to the watch

replyHandler (returnInfo);

});


}

dispatching to another queue should not be necessary. Great if you could file a bug with a simple little project where the problem reproduces; then report back here with the number and I'll make sure it gets to the right engineers promptly!

Watch Connectivity - WCSessionDelegate methods not called (simulator)
 
 
Q