Here is a Q / A link about WatchConnectivity: Send messages between iOS and WatchOS with WatchConnectivity in watchOS2
I'll give you an example go applicationContext, there are 2 other messaging methods with WatchConnectivity. Please see the WWDC2015 session video recording for them.
First you need to comply with the WCSessionDelegate protocol in the classes you want to send and receive data from / to. For example, both on the watch and on the iPhone.
Basic check before: (this is just an example, it is better to implement this)
if ([WCSession isSupported]) { WCSession *session = [WCSession defaultSession]; session.delegate = self; [session activateSession]; NSLog(@"SESSION AVAIBLE"); }
This will send data from the phone to the watch.
WCSession *session = [WCSession defaultSession]; NSError *error; [session updateApplicationContext:@{@"firstItem": @"item1", @"secondItem":[NSNumber numberWithInt:2]} error:&error];
This will receive data from the phone on the watch.
- (void) session:(nonnull WCSession *)session didReceiveApplicationContext:(nonnull NSDictionary<NSString *,id> *)applicationContext { NSLog(@"%@", applicationContext); item1 = [applicationContext objectForKey:@"firstItem"]; item2 = [[applicationContext objectForKey:@"secondItem"] intValue]; }
The WWDC2015 video on WatchConnectivity is really great, I recommend checking it out.
source share