블로그 이미지
Sunny's

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

'Setting Bundle'에 해당되는 글 1

  1. 2011.09.23 Setting Bundle 설정하기
2011. 9. 23. 18:04 IPhone

Setting Bundle 설정하기

설정하기 : 파일추가>리소스>Settings.bundle

iOS5에서 Settings.bundle 추가후 해야할 사항(iOS5 Xcode의 현재 버그임)
1) Click on the Settings.Bundle file, go over to the utilities window,and look in the File Inspector.
2) Using the drop-down, change the file type to 'Application Bundle'




- (void)applicationDidFinishLaunching:(UIApplication *)application {    
   
NSString *name = [[NSUserDefaults standardUserDefaults] stringForKey:@"name"];
   
NSLog(@"name before is %@", name);

   
// Note: this will not work for boolean values as noted by bpapa below.
   
// If you use booleans, you should use objectForKey above and check for null
   
if(!name) {
       
[self registerDefaultsFromSettingsBundle];
        name
= [[NSUserDefaults standardUserDefaults] stringForKey:@"name"];
   
}
   
NSLog(@"name after is %@", name);
}

- (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];
}


출처 : http://stackoverflow.com/questions/510216/can-you-make-the-settings-in-settings-bundle-default-even-if-you-dont-open-the-s/510329#510329
posted by Sunny's
prev 1 next