In my InterfaceController I have the following code:
@IBAction func buttonClicked() {
if (WCSession.default.isReachable) {
let message = ["Message": "Hello"]
WCSession.default.sendMessage(message, replyHandler: nil)
print ("message sent")
}
}
In ViewController I have the following code:
override func viewDidLoad() {
super.viewDidLoad()
if (WCSession.isSupported()) {
let session = WCSession.default
session.delegate = self
session.activate()
}
}
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
print ("message received")
print (message)
}
When I send a message from the Watch App, I get the following error
message sent
2017-12-03 19:33:03.903709+0530 Watch Extension[1761:74704] [WC] -[WCSession _onqueue_notifyOfMessageError:messageID:withErrorHandler:] 5BBE38F1-13C7-46E3-8E99-A874B43C6516 errorHandler: NO with WCErrorCodeDeliveryFailed
Debug window of iOS App gives me following info:
2017-12-03 19:35:28.706212+0530 WatchTest[1770:76097] [WC] -[WCSession onqueue_handleDictionaryMessageRequest:withPairingID:]_block_invoke delegate WatchTest.ViewController does not implement delegate method
2017-12-03 19:35:28.707992+0530 WatchTest[1770:76097] [WC] -[WCSession _onqueue_sendResponseError:identifier:dictionaryMessage:] identifier: 96B10064-F17B-4D4B-8F5C-1154984D5163 with WCErrorCodeDeliveryFailed
Am I missing any implementation in ViewController class? I am using Xcode 9.0
I changed the buttonClicked action method to following:
The sendMessage probably requires the reply and error handlers to be defined.