我想將數據從iPhone傳遞到Apple Watch。我嘗試了一切,但是當我使用didReceiveUserInfo
函數時,沒有任何反應,我檢查WCSession是否兼容。WatchOS2連接框架不起作用
代碼在我的iPhone:我的Apple關注
if(ipField.text != ""){
do {
try watchSession?.transferUserInfo(["name" : "test"])
print("context update")
} catch let error as NSError {
NSLog("Updating the context failed: " + error.localizedDescription)
print("failed")
}
代碼:
func session(session: WCSession, didReceiveUserInfo userInfo: [String : AnyObject]){
let Value = userInfo["name"] as? String
self.currentIpLabel.setText(Value)
print("done1")
}
WCSESSION檢查iPhone:
if (WCSession.isSupported()) {
let session = WCSession.defaultSession()
session.delegate = self
session.activateSession()
print("SUPPORT OK")
}
WCSESSION檢查蘋果手錶
if(WCSession.isSupported()){
watchSession = WCSession.defaultSession()
// Add self as a delegate of the session so we can handle messages
watchSession!.delegate = self
watchSession!.activateSession()
}
你是否在didTransferUserInfo回調中發送任何錯誤返回?如果沒有,請張貼代碼激活會話的雙方以及代碼發送用戶信息和代碼來接收它 – ccjensen
@ccjensen嗨,我在我的問題中添加了代碼。我沒有得到任何錯誤。 – LifeOS
你有解決方案嗎? @ccjensen – LifeOS