2015-11-06 21 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