Spa*_*Dog 8 iphone settings.bundle
我创建了一个随Root.plist文件和本地化目录en.lproj一起提供的Settings.bundle.
我编辑了Root.plist并添加了几个我想要的应用程序设置.
当我从iPhone删除应用程序并安装它并第一次运行时,我读取的所有设置都返回错误的值.例如:
highQualityFlag = [[[NSUserDefaults standardUserDefaults] stringForKey:@"qualityFlag"] boolValue];
Run Code Online (Sandbox Code Playgroud)
即使设置默认值为YES,该标志也为NO.
如果我在设置上更改了某些内容并再次运行,则所有后续运行都会给出正确的值(??)
我该如何解决?
谢谢
0x8*_*00d 24
试试这个:
- (void)registerDefaultsFromSettingsBundle
{
NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
if(!settingsBundle)
{
//NSLog(@"Could not find Settings.bundle");
return;
}
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:@"Root.plist"]];
NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"];
NSMutableDictionary *defaultsToRegister = [[NSMutableDictionary alloc] initWithCapacity:[preferences count]];
for(NSDictionary *prefSpecification in preferences)
{
NSString *key = [prefSpecification objectForKey:@"Key"];
if(key)
{
[defaultsToRegister setObject:[prefSpecification objectForKey:@"DefaultValue"] forKey:key];
}
}
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister];
[defaultsToRegister release];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self registerDefaultsFromSettingsBundle];
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7234 次 |
| 最近记录: |