根据我的经验,手表操作系统非常挑剔,尤其是在使用旧款手表时。话虽如此,我认为问题的答案是:“假设会话已准备好接受activationDidCompleteWith 中的通信是否不安全?” 是的,假设这一点是不安全的。
在我自己的应用程序中,我的情况与您的情况非常相似,我通过发送消息解决了它,直到收到回复。
// false until a response is received from the phone
let receivedResponse: Bool = false
// function that sends the message
func requestResponse() {
guard WCSession.default.isReachable else {
print("Phone not reachable")
return
}
// callback that handles response
let responseHandler: ([String: Any]) -> () = { response in
receivedResponse = true
callback(response)
}
WCSession.default.sendMessage(["Request": "Response"],
replyHandler: responseHandler) { error in
print(error.localizedDescription)
}
}
// timer that calls the request function repeatedly
let retryTimer = Timer.scheduledTimer(withTimeInterval: 1,
repeats: true) { timer in
if receivedResponse {
// we know we got a response so clean up timer
timer.invalidate()
}
requestResponse()
}