I have read the q/a below, and it's great. This is exactly what I'm doing in a test project, and it works fine.
I've now created my real project, but in the Watch extension, session: didReceiveApplicationContext:
does not fire.
Here is my send code:
-(void)sendPlistToWatch:(NSMutableDictionary *)dictionary {
NSLog(@"%s", __FUNCTION__);
if ([WCSession defaultSession]) {
NSDictionary *applicationDict = @{@"Favorites.plist":dictionary};
[[WCSession defaultSession] updateApplicationContext:applicationDict error:nil];
NSLog(@"sent dictionary");
} else {
NSLog(@"not paired");
}
}
And this is the receive code on the watch:
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
if ([WCSession isSupported]) {
[self.session activateSession];
self.session = [WCSession defaultSession];
self.session.delegate = self;
}
}
- (void)willActivate {
[super willActivate];
}
- (void)didDeactivate {
[super didDeactivate];
}
- (void)session:(nonnull WCSession *)session didReceiveApplicationContext:(nonnull NSDictionary<NSString *,id> *)applicationContext {
NSString *string = [applicationContext objectForKey:@"dictionary"];
NSMutableDictionary *dictionary = [applicationContext objectForKey:@"dictionary"];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog (@"applicationContext: %@", applicationContext);
});
}
Send messages between iOS and WatchOS with WatchConnectivity in watchOS2
I've watched the WWDC connectivity session, and find this site very helpful.
Any ideas (perhaps it's not code, but a missing or incorrect plist setting?)