我正在开发一款使用WCSession
方法 在iPhone和Apple Watch之间共享数据的应用程序sendMessage:replyHandler:errorHandler:
实现该方法后,我收到如下错误:
WCSession _onqueue_notifyOfMessageError:withErrorHandler:errorHandler:YES,WCErrorCodeDeliveryFailed.
错误=无法传递Payload.
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 = …
Run Code Online (Sandbox Code Playgroud)