这听起来可能很菜鸟!我想检查用户是否第二次进入我的应用程序,以便保留我正在使用的运行计数NSUserDefaults
。我已经在我的中实现了以下代码rootViewController
's viewDidLoad
method:
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSLog(@"hello %ld", (long)[userDefaults integerForKey:@"runCount"]);
if ([userDefaults integerForKey:@"runCount"] != 1) {
//not the 2nd run
[userDefaults setInteger:1 forKey:@"runCount"];
NSLog(@"not 2nd run");
} else {
//second run or more
NSLog(@"2nd run");
}
[userDefaults synchronize];
一切正常,但问题是,当我根据卸载(删除并重新安装)应用程序时here https://stackoverflow.com/questions/9163798/is-data-stored-in-nsuserdefaults-persists-through-application-updates-and-on-app and here https://stackoverflow.com/questions/7520800/are-values-stored-in-nsuserdefaults-removed-when-the-app-that-put-them-there-is数据应该被清除,但事实并非如此,重新安装应用程序后,以前的数据仍然显示。
我正在使用 xCode6-beta 在 iOS 模拟器上运行我的应用程序,并针对 iOS 8 上的应用程序
我认为这是由于 iOS8 Beta 模拟器中的一个错误造成的。
预期的行为是,当删除应用程序时,该应用程序的 NSUserDefaults 也会被删除。
- 然而,NSUserDefaults 是NOT当您从模拟器中删除应用程序时被删除。
- 当您从运行 iOS8 的物理设备中删除它们时,它们会被正确删除。
目前,一个快速而烦人的解决方案是单击“iOS Simulator”->“重置内容和设置”。
带有 Simulator 10 的 Xcode 9.2 仍然存在此问题。菜单选项现在是硬件..删除所有内容和设置
顺便说一句,我提交了一份错误报告
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)