Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCSession sendMessage:replyHandler error code 7014 (WCErrorCodeDeliveryFailed)

Tags:

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

like image 349
gsempe Avatar asked Oct 18 '15 16:10

gsempe


2 Answers

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.

like image 115
Peter Robert Avatar answered Sep 16 '22 22:09

Peter Robert


In my case, I had to implement both delegates:

  1. The one without any replyHandler

    func session(_ session: WCSession,                  didReceiveMessage message: [String : Any]) 
  2. 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

like image 43
staticVoidMan Avatar answered Sep 18 '22 22:09

staticVoidMan