watchkitwatchconnectivity

ApplicationContext property always return an Empty dictionary


I'm trying to get the latest data from a WCSession and I can't understand why even if I've just received the didReceiveApplicationContext call. More details are available directly into the code:

//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)
}

I expect the applicationContext property to be always updated with the latest information set using the updateApplicationContext since I always use the same WCSession obtained with WCSession.defaultSession for both the iOS and Watch app. Is there anything that I'm misinterpreting about connectivity?!


Solution

  • receivedApplicationContext is what you are looking for. applicationContext's contents is the stuff you've sent out, not received.