【发布时间】:2015-11-06 11:36:26
【问题描述】:
我正在尝试从WCSession 获取最新数据,即使我刚刚收到didReceiveApplicationContext 电话,我也不明白为什么。
更多细节可直接在代码中获得:
//Watch Code
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
if (WCSession.isSupported()) {
session = WCSession.defaultSession()
session?.delegate = self
session?.activateSession()
verifyUser()
}
}
// 1. This function is called, with the applicationContext data
func session(session: WCSession, didReceiveApplicationContext applicationContext: [String : AnyObject]) {
print("CONTEXT \(applicationContext)")
}
// 2. I manually trigger this call from the watch with a button.
// even if I call this function after the previous function (1) it always print an Empty ([:]) applicationContext.
@IBAction func printContext(){
print(session?.applicationContext)
}
我希望applicationContext 属性始终使用updateApplicationContext 设置的最新信息进行更新,因为我始终使用WCSession.defaultSession 获得的相同WCSession 用于iOS 和Watch 应用程序。我对连接有什么误解吗?!
【问题讨论】:
标签: watchkit watchconnectivity