2
使用NSUserDefaults進行設置/接收數據的真正基本測試。我的iPhone應用程序正在工作並設置數據很好,但在手錶上,它已經空了。WatchKit NSUserDefaults爲空
我已經爲兩者啓用了應用程序組,並驗證了它們使用相同的組是相同的。每個權利文件都有點相同。
在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"]);
}
和所有我得到的回覆是:
playerName:(空)
我我不得不失去如此明顯的東西。當我NSLog它在iphone端,它出來就很好,所以我知道它是正確保存。
檢查。檢查。檢查。這是奇怪的部分。開始感到沮喪,所以我去了開發者門戶網站,把我的應用程序組和我所有的舊測試項目都從頭開始擦乾淨。第二次就像魅力一樣工作......哦,也許我會把它記錄到Gremlins。 :-) – Drew