我正在开发我的应用程序的beta版本,我需要确保在最终发布的版本中,曾经参与beta测试的用户在第一次启动应用程序时会使用完全清除的用户默认设置...(我无法更改Bundle ID)。
1) 有没有办法通过编程方式清除用户默认设置?
2) 将此应用程序沙盒化以进行App Store提交是否有帮助?
我正在开发我的应用程序的beta版本,我需要确保在最终发布的版本中,曾经参与beta测试的用户在第一次启动应用程序时会使用完全清除的用户默认设置...(我无法更改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.");}
}
+[NSUserDefaults resetStandardUserDefaults]有什么问题?如果您已经正确注册了默认偏好设置,这一行代码将重置为您提供的注册的默认偏好设置。
`[NSUserDefaults resetStandardUserDefaults];
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];`
但是在def
中我仍然发现用户生成的数据。
我错过了什么? - MatterGoal
removeObjectForKey
操作,或者将您的NSUserDefaults
替换为一个空字典。但我列出的方法应该是有效的。 - Baub