ios - How to send data from Iphone to Apple Watch in OS2 in Objective-C -
i've seen similar question posted on how send data , forth in swift. i'm asking same question in objective-c. i've viewed apple's transition docs.
i work best clear examples, rather lecture material. if has implemented , wouldn't mind sharing, appreciated.
here´s link q/a watchconnectivity: send messages between ios , watchos watchconnectivity in watchos2
i give example go applicationcontext, there 2 other messaging techniques watchconnectivity. please watch wwdc2015 session video those.
first need conform wcsessiondelegate protocol in classes want send , receive data from/to. e.g both on watch , iphone.
basic checking before: (this example, implement better this)
if ([wcsession issupported]) { wcsession *session = [wcsession defaultsession]; session.delegate = self; [session activatesession]; nslog(@"session avaible"); } //objective-c if ([[wcsession defaultsession] isreachable]) { nslog(@"session reachable"); }
this send data phone watch.
wcsession *session = [wcsession defaultsession]; nserror *error; [session updateapplicationcontext:@{@"firstitem": @"item1", @"seconditem":[nsnumber numberwithint:2]} error:&error];
this receive data phone on 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 great, recommend check out.
Comments
Post a Comment