【发布时间】:2015-05-13 21:02:24
【问题描述】:
在使用 NSUserDefaults 设置/接收数据时进行真正的基本测试。我的 iPhone 应用程序工作正常,数据设置正常,但在手表上,它显示为空。
我为两者启用了应用程序组,并使用同一个组验证了它们是相同的。每一个的授权文件都是一样的。
在 ViewController.m 中
defaults = [[NSUserDefaults alloc] initWithSuiteName:@"com.defaultmethod.share"];
[defaults setObject:playerName forKey:@"playerName"];
[defaults synchronize];
在 InterfaceController.m 中
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
// Configure interface objects here.
defaults = [[NSUserDefaults alloc] initWithSuiteName:@"com.defaultmethod.share"];
[defaults synchronize];
}
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
NSLog(@"playerName: %@", [defaults objectForKey:@"playerName"]);
}
我得到的只是:
玩家姓名:(空)
我必须遗漏一些如此明显的东西。当我在 iphone 端 NSLog 时,结果很好,所以我知道它保存正确。
【问题讨论】:
标签: ios objective-c nsuserdefaults watchkit xcode-6.2