我正在使用WatchKit 2.0,并且注意到一种非常奇怪的行为。如果我使用我的手表应用程序超过5分钟,我开始从WCSession sendMessage调用中获取超时错误,该调用以前已经被调用并成功完成。我将错误打印为:
Error Domain=WCErrorDomain Code=7012 "Message reply took too long." UserInfo={NSLocalizedDescription=Message reply took too long., NSLocalizedFailureReason=Reply timeout occured.}我仍然可以在不同的Interface Controllers中打其他的电话,但是我一直在Interface Controllers中接到errorHandlers的呼叫,它已经关闭了(在顶部使用后退按钮)。
有人知道是什么导致了这种行为吗?我不会在代码中结合层次化和基于页面的接口样式,在使用应用程序时,所有的东西都会在最初的5分钟内运行。
更新
以下是代码:
if WCSession.isSupported() {
// Set the session to default session singleton
let session = WCSession.defaultSession()
// Fire the message to iPhone app
session.sendMessage(["action": "getProfile", "memberId": citizen!.memberId], replyHandler: { (response) -> Void in
if response["messageData"] != nil {
// There is data in the reply
let jsonObject = JSON(response["messageData"]!)
...
// Display the profile details
self.displayProfileDetails()
} else if response["error"] != nil {
// Get the error message and display it
self.showAlert(nil, message: WatchUtils.getErrorString(response["error"]), action: .GET_PROFILE)
}
}, errorHandler: { (error) -> Void in
print("error: \(error)")
// Show alert
self.showAlert(nil, message: NSLocalizedString("watch_connectivity_error", comment: "Watch can't connect to phone"), action: .GET_PROFILE)
})
}replyHandler最初被调用,但由于某种原因,在5分钟后调用了errorHandler,并且每隔几秒钟就会被调用一次。
发布于 2016-04-01 20:44:57
几个月前我也遇到过同样的问题。我想出的解决方案是使用一个变量来存储我给出的上次请求的id,例如
self.lastCallId = "watch_load_clients“
如果没有收到匹配的id (我还将id发回),则忽略请求。
我觉得这只是蓝牙的问题。
编辑:还有,你是在提出请求,却没有收到回复吗?当你的问题发生的时候,情况就是这样。
https://stackoverflow.com/questions/36365260
复制相似问题