关于从iPhone应用程序到苹果手表的共享数据,我遇到了问题.我尝试下面的代码来分享NSMutablearray到苹果手表,但它无法正常工作. NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:arrSta
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:arrStartScore]; NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.test.StartScore"]; [defaults setObject:encodedObject forKey:@"WatchHomeViewTableList"]; [defaults synchronize];
用于将数据检索到Apple Watch
NSUserDefaults *myDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.test.StartScoreCheck"]; arrStartScore = [myDefaults objectForKey:@"WatchHomeViewTableList"]; NSLog(@"dict....%@",arrStartScore);要将数据从手机发送到手表,请使用此代码.
WCSession *session = [WCSession defaultSession]; NSError *error; [session updateApplicationContext:@{@"message": yourArray} error:&error];
要从手表上的手机接收数据:
- (void) session:(nonnull WCSession *)session didReceiveApplicationContext:(nonnull NSDictionary<NSString *,NSMutableArray *> *)applicationContext { }
您可以使用didReceiveApplicationContext访问您的数组
[applicationContext objectForKey:@"message"];