Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCErrorCodeDeliveryFailed: Payload could not be delivered

I'm working on an app that share data between iPhone and Apple Watch, using WCSession method sendMessage:replyHandler:errorHandler:

After implementing that method I get the error like:

WCSession _onqueue_notifyOfMessageError:withErrorHandler: errorHandler: YES with WCErrorCodeDeliveryFailed.

Error = Payload could not be delivered.

import Foundation
import WatchKit
import WatchConnectivity

class ResultInterfaceController: WKInterfaceController, WCSessionDelegate {

override func awake(withContext context: Any?) {
    super.awake(withContext: context)

    let applicationData = ["name": "ViratKohli"]
    self.sendToPhone(data: applicationData)
}

func sendToPhone(data: [String: Any]) {

    if WCSession.isSupported() {

        let session = WCSession.default
        session().delegate = self
        session().activate()

        if WCSession.default().isReachable {

            session().sendMessage(data, replyHandler: {(_ replyMessage: [String: Any]) -> Void in

                print("ReplyHandler called = \(replyMessage)")
                WKInterfaceDevice.current().play(WKHapticType.notification)
            }, 
            errorHandler: {(_ error: Error) -> Void in

                print("Error = \(error.localizedDescription)")
            })
         }
    }
}
....

Any help appreciated.

like image 857
SahyadriChava Avatar asked Feb 10 '17 04:02

SahyadriChava


1 Answers

  1. Do you have session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) on ios side's WCSessionDelegate?
  2. Are you calling replyHandler() inside this method?

Pay attention that session(_ session: WCSession, didReceiveMessage message: [String : Any]) will be called only for messages sent without replyHandler.

like image 112
abjurato Avatar answered Oct 11 '22 16:10

abjurato