2017-03-06 129 views
0

我正在使用WCSession對象通過sendMessage(_:replyHandler:errorHandler:)將手錶應用程序(watchOS 3.3 beta 4)的數據發送回相應的iOS應用程序。按照documentation from AppleWCSession sendMessage何時無法在後臺喚醒iOS應用程序?

Calling this method from your WatchKit extension while it is active and running wakes up the corresponding iOS app in the background and makes it reachable.

然而,我發現,如果WCSession對象的isReachable財產調用sendMessage之前false,該消息未能與此錯誤發送: Error Domain=WCErrorDomain Code=7007 "WatchConnectivity session on paired device is not reachable." UserInfo={NSLocalizedDescription=WatchConnectivity session on paired device is not reachable.}

會話被激活,所以我相信這個sendMessage調用應該使iOS應用程序可訪問,然後發送,但這不會發生。

在什麼情況下會發生這種情況,是否有任何解決方法?

+0

您如何測試?這是在設備上,是手機和手錶目前與藍牙連接? – Cobra

+0

是的,這是在與手機藍牙連接的設備上。它通常使電話可達,但在<10%的時間內失敗。 –

回答

0

a)如果你正在使用sendMessage(_, replyHandler:_, errorHandler:_)與非空回覆事件,IOS對方的WCSessionDelegate應該有session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void)方法來實現,並且消息將被稱爲交付一旦你會打電話給replyHandler(_:)這個方法裏面。如果這個方法沒有實現,消息不會得到響應,你會得到超時錯誤。

b)另外,我注意到WCSessionDelegate的任何session(_ session: WCSession, didXXX: XXX)方法中的代碼都在執行時,消息不會被髮送。看起來像所有這些都在一個串行背景隊列中執行。

相關問題