2015-11-06 49 views
3

我试图从WCSession获取最新数据,我无法理解为什么即使我刚刚收到了didReceiveApplicationContext调用。 更多详细信息,请直接到代码:ApplicationContext属性总是返回一个空字典

//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同时为iOS和观察获得相同WCSession集最新的信息不断更新应用程序。有什么我误解连接?!

回答

9

receivedApplicationContext是你在找什么。 applicationContext的内容是你发送的东西,没有收到。

+1

so true .... :) – brush51