0

I'm using a WCSession object to send data from a watch app (watchOS 3.3 beta 4) back to the corresponding iOS app via sendMessage(_:replyHandler:errorHandler:). According to the documentation from Apple:

Calling this method from your WatchKit extension while it is active and running wakes up the corresponding iOS app in the background and makes it reachable.

However, I find that if the isReachable property of the WCSession object is false before calling sendMessage, the message fails to send with this error: Error Domain=WCErrorDomain Code=7007 "WatchConnectivity session on paired device is not reachable." UserInfo={NSLocalizedDescription=WatchConnectivity session on paired device is not reachable.}

The session is activated, so I believe this sendMessage call is supposed to make the iOS app reachable and then be sent, but this is not happening.

Under what circumstances does this happen, and are there any workarounds?

Jeff V
  • 571
  • 1
  • 5
  • 17
  • How are you testing? Is this on device and are the phone and Watch currently connected with Bluetooth? – Cobra Mar 13 '17 at 02:02
  • Yes, this is on the device with a Bluetooth connection to the phone. It usually makes the phone reachable, but fails < 10% of the time. – Jeff V Mar 14 '17 at 04:00

1 Answers1

-1

a) If you are using sendMessage(_, replyHandler:_, errorHandler:_) with non-nil reply handler, ios counterpart's WCSessionDelegate should have session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) method implemented, and message will be referred to as delivered once you'll call replyHandler(_:) inside this method. If this method is not implemented, message will not get response and you'll get timeout error.

b) Also, I've noticed that messages not be delivered while code in any of session(_ session: WCSession, didXXX: XXX) methods of WCSessionDelegate is executing. Looks like all of them are being executed in one serial background queue.

abjurato
  • 1,439
  • 11
  • 17