目的:我想在運行時將iPhone應用程序首選項如何在運行時更改iphone應用程序首選項設置?
在Setting.Bundle我有標題=版本和默認值= 1.0
所以在運行時是否有可我不得不新版本更改iPhone應用程序首選項默認值。但我無法這樣做。它顯示,而不是1.1
我不知道什麼是錯在我的代碼1.0
代碼:
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) {
if([key isEqualToString:@"name_preference"])
{
NSString *a=[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
[defaultsToRegister setObject:a forKey:key];
}
else {
[defaultsToRegister setObject:[prefSpecification objectForKey:@"DefaultValue"] forKey:key];
}
}
}
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister];