我正在开发我的应用程序的 beta 版本,我需要确保在首次启动最终版本时,已经是 beta 测试人员的用户将以完全清晰的用户默认设置启动应用程序...(i无法更改 bundle ID)。
1) 有没有办法以编程方式清除用户默认值?
2) 将此应用程序沙箱化以提交 App Store 对我有帮助吗?
最佳答案
您可以像这样删除它:
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
要在第一次启动时运行它,我只需设置一个 BOOL 标志。一种方法如下:
- (void)applicationDidFihishLaunching
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if ([[prefs objectForKey:@"secondOrMoreTimeLoading"]boolValue]==0) //so if there is nothing there...
{
NSLog(@"This is the first time the user has loaded the application. Welcome!");
//run the code above here, then change our flag to 1 so that it never runs this again (unless the prefs are reset elsewhere)
[prefs setObject:[NSNumber numberWithBool:1] forKey:@"secondOrMoreTimeLoading"];
}
else{NSLog(@"Welcome back, user.");}
}
关于macos - 在 OS X 应用程序中以编程方式清除用户默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8158592/