i have read q/a below, , it's great. i'm doing in test project, , works fine.
i've created real project, in watch extension, session: didreceiveapplicationcontext: not fire.
here 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 receive code on 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 , watchos watchconnectivity in watchos2
i've watched wwdc connectivity session, , find this site helpful.
any ideas (perhaps it's not code, missing or incorrect plist setting?)
i've run similar issue (ios 9.3, watchos 2.2) session: didreceiveapplicationcontext: delegate method wouldn't fire when expected. appears there's undocumented behavior whereby if dictionary matches previous value sent, call updateapplicationcontext() fails silently, neither sending dictionary nor throwing error (see https://forums.developer.apple.com/thread/46107).
the solution offered in thread add nsuuid().uuidstring every dictionary while testing. worked me.
Comments
Post a Comment