を使用しWatchKit 2.0ていますが、非常に奇妙な動作に気づいています。Watch アプリを 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続けます。errorHandlersInterface Controllers
この動作の原因を知っている人はいますか? コード内で階層型とページベースのインターフェイス スタイルを組み合わせていません。アプリケーションを使用している間、最初の 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が呼び出され、数秒ごとに呼び出され続けます。