Iphone中的setting bundle

Iphone中的setting bundle
最近把xcode升级后发现加入settingbundle取出的defaultValue一直是nil
一直找不到原因
所以就用以下方法了,希望能对大家有帮助

- ( void )initvalue
{
    NSString 
*url=[[NSUserDefaults standardUserDefaults] objectForKey:kConnection];
    
if (url==nil) {
        NSString 
*stringBundle=[[NSBundle mainBundle] bundlePath];
        NSString 
*settingBundle=[stringBundle stringByAppendingPathComponent:@"Settings.bundle"];
        NSString
*listBundle=[settingBundle stringByAppendingPathComponent:@"Root.plist"];
        NSDictionary
*rootDict=[NSDictionary dictionaryWithContentsOfFile:listBundle];
        NSArray
*array=[rootDict objectForKey:@"PreferenceSpecifiers"];
        NSDictionary
*preItem;
        NSString
*connection=nil;
        
for (preItem in array) {
            NSString
*key=[preItem objectForKey:@"Key"];
            id defaultValue
=[preItem objectForKey:@"DefaultValue"];
            
if ([key isEqualToString:@"connection"]) {
                connection
=@" http://www.baidu.com";
            }

        }

        NSDictionary 
*dictionary=[[NSDictionary alloc]initWithObjectsAndKeys:connection,@"connection",nil];
        [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [dictionary release];
        [stringBundle release];
        [rootDict release];
        [preItem release];
    }

}
这只是初始化Root.plist里的值,在这里我加入了一个PSTextFieldSpecifier,

你可能感兴趣的:(Iphone中的setting bundle)