我正在开发一款在 iPhone 和 Apple Watch 之间共享数据的应用程序,使用WCSession
方法sendMessage:replyHandler:errorHandler:
实施该方法后,我收到如下错误:
WCSession _onqueue_notifyOfMessageError:withErrorHandler: errorHandler: YES 且 WCErrorCodeDeliveryFailed。
错误 = 无法传送有效负载。
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)")
})
}
}
}
....
任何帮助表示赞赏。
- 你有
session(_ session: WCSession, didReceiveMessage
message: [String : Any], replyHandler: @escaping ([String : Any]) ->
Void)
在ios端的WCSessionDelegate?
- 你打电话吗
replyHandler()
在这个方法里面?
请注意session(_ session: WCSession, didReceiveMessage message: [String : Any])
仅当发送的消息没有replyHandler 时才会被调用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)