I'm passing (from iOS) some data (colors), but when I receive the data (colors) on the other side (WatchKit) it only shows the one most recent dictionary item.
iOS function to pass data:
publicData.performQuery(query, inZoneWithID: nil) { results, error in
if error == nil { // There is no error
for play in results! {
let newPlay = Play()
newPlay.tColor = play["TColor"] as! String
do {
try WatchSessionManager.sharedManager.updateApplicationContext(["color" : newPlay.tColor])
NSLog("Dict: %@", ["color" : newPlay.tColor])
} catch {
print(error)
}
self.objects.append(newPlay)
}
All three color items show up in NSLog from function to pass data.
Dict: {
color = FDB927;
}
Dict: {
color = 000000;
}
Dict: {
color = 000000;
}
WatchKit function to receive data:
func session(session: WCSession, didReceiveApplicationContext applicationContext: [String : AnyObject]) {
NSLog("Application Context %@", applicationContext.description)
dispatch_async(dispatch_get_main_queue()) { [weak self] in
self?.dataSourceChangedDelegates.forEach { $0.dataSourceDidUpdate(DataSource(data: applicationContext))}
}
}
But on WatchKit side, only the last Dictionary item shows up in NSLog:
Application Context ["color": 000000, "matchup"]
Any help greatly appreciated. Thanks!
This is exactly how the WatchConnectivity's updateApplicationContext works (only sends the most recent). If you want all the dicts to arrive you should instead use the transferUserInfo API, which queues up the dictionaries for delivery rather than just delivering the most recent one.
Communicating with a Counterpart
You can communicate with a counterpart app in the following ways:
You have to use sendMessage:replyHandler:errorHandler: instead of updateApplicationContext:error:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With