我有一个Apple Watch应用程序,我使用Parse来帮助构建。当我从应用程序收到通知时,会有两次。我怀疑有一个是送到我的手机,手表显示,第二个实际送到手表。这很烦人。我的InterfaceController设置在Watch App(watchOS 1)上看起来像这样:
- (void)awakeWithContext:(id)context {
[Parse setApplicationId:@"ID"
clientKey:@"KEY"];
NSUserDefaults *testDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.company.appName"];
NSString *theirUser = [testDefaults objectForKey:@"sessiontoken"];
NSString *theirPass = [testDefaults objectForKey:@"password"];
NSLog(@"%@", theirPass);
if (![testDefaults objectForKey:@"sessiontoken"]) { // No user logged in
NSLog(@"No");
self.loginLabel.hidden = NO;
}
else {
[PFUser becomeInBackground:theirUser block:^(PFUser *user, NSError *error) {
if (error) {
// The token could not be validated.
} else {
// The current user is now set to user.
}
}];
self.loginLabel.hidden = YES;
}
[super awakeWithContext:context];
// Configure interface objects here.
} 我设置它,以便当用户登录iPhone时,它在NSUserDefaults中存储一个值为“sessiontoken”的键。如果在手表上找不到,登录标签会告诉他们首先登录iPhone。一旦检测到它,它就会消失。有什么建议吗?