我有一個文件在從的appDelegate的appDidFinishLoading方法負載使用URL值,檢查一個應用程序,我理應店在NSUserDefaults的設置根的plist:NSUserDefaults的設置包的plist
NSString *pathStr = [[NSBundle mainBundle] bundlePath];
NSString *settingsBundlePath = [pathStr stringByAppendingPathComponent:@"Settings.bundle"];
NSString *finalPath = [settingsBundlePath stringByAppendingPathComponent:@"Root.plist"];
NSDictionary *settingsDict = [NSDictionary dictionaryWithContentsOfFile:finalPath];
NSArray *prefSpecifierArray = [settingsDict objectForKey:@"PreferenceSpecifiers"];
NSDictionary *prefItem;
for (prefItem in prefSpecifierArray){
NSString *keyValueStr = [prefItem objectForKey:@"Key"];
if ([keyValueStr isEqualToString:kFirstNameKey]){
nsUserDefURL = [prefItem objectForKey:@"DefaultValue"];
}
if ([keyValueStr isEqualToString:kSecondNameKey]){
NSLog(@"You are using local data:%@",[prefItem objectForKey:@"DefaultValue"]);
}
}
NSLog(@" this is the url == %@", nsUserDefURL);
// since no default values have been set (i.e. no preferences file created), create it here
NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:nsUserDefURL,kFirstNameKey,@"YES",kSecondNameKey,nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
[[NSUserDefaults standardUserDefaults] synchronize];
一些靜:
NSString *kFirstNameKey = @"url";
NSString *kSecondNameKey = @"Web DataSource";
當我NSLog的nsUserDefURL,我仍然得到設置plist默認值。我進入應用程序的設置(不知道我可以在模擬器中這樣做),然後我修改了url字段中的值,但是我仍然得到test2.xml值,它是設置根目錄中的默認佔位符值plist中。
這裏是plist中:
或者它是設置包不會在Xcode的模擬器工作?