I have a Watch OS 2 application that communicates with the iOS app via WCSession
method sendMessage:replyHandler:errorHandler:
The iOS application reply correctly but time to time I get the error with code 7014
of domain WCErrorDomain
: "Payload could not be delivered"
It happens more often when the iOS application is not foreground.
I do not find any solution of this problem, I hope one of you know a solution to this problem
For anyone having issues on iOS10 beta 6 and GM, and you are using Swift3, the solution is to change the delegate function header in the iOS app to the following:
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
Note the @escaping and the Any instead of the AnyObject type.
In my case, I had to implement both delegates:
The one without any replyHandler
func session(_ session: WCSession, didReceiveMessage message: [String : Any])
The one with replyHandler
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void)
If you send a message without a replyHandler
then the first delegate runs.
If you send a message with a replyHandler
then the second delegate runs.
In some cases I was sending only a message, and in other cases I was sending a message and expecting a reply from the counterpart.
BUT... I had implemented only the second delegate -_-
Anyways, eventually to reduce duplicate code I implemented a common method and ended up with:
func session(_ session: WCSession, didReceiveMessage message: [String : Any]) { handleSession(session, didReceiveMessage: message) } func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) { handleSession(session, didReceiveMessage: message, replyHandler: replyHandler) } //Helper Method func handleSession(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: (([String : Any]) -> Void)? = nil) { //Common logic }
Watch OS 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With