WCSession sendmessage Watch to Phone not working

WCSession sendmessage from iPhone to Watch is working (Beta 1 to 3), but I've not been able to get a message from the Watch to the Phone. Watch to phone doesnt work in the sample app (Potloc) either, although under current betas (XCode, iOS and Watch) Potloc will not install on the watch and I haven't bothered to find out why.


I can't get debug to work with the Watch app, despite workarounds suggested elsewhere, so it's hard to tell what's going on with WCSession.


Has anyone got WCSession sending messages from watch to phone?


Cheers.

this should work just fine. Please file a bug and include a small sample projecy where this reproduces; great if you could report back here with the radar number so I can help direct it to the right engineers.

Thank you Viking.


I'm doing a test project just for iPhone - Watch communication, so as to ensure there's nothing in my actual App project that's causing problems.


I'll lodge a bug report, if required, and repost later today Sydney time.


Regards,


Michael

I constructed a test app that sends context information from phone to watch and watch to phone, and also a message from watch to phone and phone to watch. I got all communications working, although the watch to phone message seemed not to be getting through in earlier versions of the test app.


Context information to/from the watch is transferred immediately. A message from the phone to the watch is also transferred immediately. However, a message (sendmessage) from the watch to the phone takes at least 5 seconds and sometimes over 20 seconds - the average being about 12 seconds. This occurs in the simulator (iPhone 6 & Watch 38mm) and also with my actual devices (iPhone 5S and Watch 38mm). Both actual devices' apps were active at the time of the tests. The Watch passcode lock is disabled.


Should I lodge a bug report?


Regards,


Michael

Yes, please!


This is definitely not expected performance for sendMessage. Please include the test project you made and we'll see if we can reproduce or otherwise we'll get things set up so we can capture debug information from your devices.

Thanks Viking.


The bug report number is

21822565


Regards,


Michael

Sending messages from the watch to the phone works fine for my app. When the WCSession delegate receives the message, have you wrapped your handling code in a dispatch_async? I am not sure but as far as I know the delegate method gets called on another thread. I would make a NSLog call on the main runloop to see if there is really a delay in receiving the message. In my app the receiver gets the data directly.

Thank you Arnfried.

I had used dispatch_async on both sides for both context and messages. However, I had misplaced my test on the phone app for if the message had been received: a "senior's moment", which unfortunately is happening more frequently as I pass the mid-sixties!

Interestingly, the WCSessionDelegate Protocol Reference for didReceiveApplicationContext does not mention being called on a background thread, but when I remove the dispatch_asynch block then context update is also delayed.

I think it was mentioned in the WWDC video. But when you described your problem it reminded me to the same delay effect I had with silent push notifications some month ago 😉

That's a good suggestion, Arnfried!


As for how this is communicated; the comment above the protocol in the WCSession header describes where the callbacks will occur:

<...>
/* ----------------------------- WCSessionDelegate -----------------------------
*  The session calls the delegate methods when content is received and session
*  state changes. All delegate methods will be called on the same queue. The
*  delegate queue is a non-main serial queue. It is the client's responsibility
*  to dispatch to another queue if neccessary.
*/
@protocol WCSessionDelegate <NSObject>
<...>

I had the same problem and finally resolved it. Somehow I managed to install/leave beta 3 on my watch and install beta 4 on my iPhone. Not sure how I did that, but it was the cause of the problem.

I am using Xcode 12.0.1 and still facing the same issue.

In my Watch Extension code I have create a WCSession object and Assigning the delegate in the Wake method.

On a button click sending the send message call.

In my Companion iOS app, I have setup the WCSession object and assigned the delegate in the ViewDidLoad method.

Also setup the delegate method didReceiveMessage and didReceiveMessage:replyhandler.

I followed below Steps to run the application.
  1. Installed the iOS app on Device.

  2. Stop the xcode, and manually launch the iOS app(Companion app).

  3. Selected the WatchApp target and run it on Watch Device through the Xcode.

  4. It puts my iOS app in background.

  5. When I click on Button in my Watch Device. It is calling the send message method but not getting the Message output in my iOS app.

WCSession sendmessage Watch to Phone not working
 
 
Q