Previously I read posts with same problem but my question persists. My app needs to read firstly a plist file to get some parameters and, when loaded on device, is unable to read default settings plist (working on simulator). One solution should be copy that plist into documents directory, but only this one? Is device unable to read user defaults set in plist? if I copy it to docs directory, will device be able to associate keys for plist if has another location? I need to read user defaults before executing any function. Thank you.
-(void)loadSettings
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
self.userID = [[NSUserDefaults standardUserDefaults] stringForKey:@"userID"];
self.nom2 = [[NSUserDefaults standardUserDefaults] stringForKey:@"t2"];
self.nom3 = [[NSUserDefaults standardUserDefaults] stringForKey:@"t3"];
self.nom4 = [[NSUserDefaults standardUserDefaults] stringForKey:@"t4"];
self.currentGlobal = [[NSUserDefaults standardUserDefaults] stringForKey:@"versionApp"];
NSLog(@"Version App = %@", currentGlobal);
self.colorTab = [[NSUserDefaults standardUserDefaults] stringForKey:@"color"];
firstBoot = [[NSUserDefaults standardUserDefaults] boolForKey:@"firstBoot"];
[defaults synchronize];
}
You do no need to copy the plist for the standardUserDefaults to the documents directory. You should let iOS create this file on its own and not include it with your app. If you need to set defaults, then you should use the registerDefaults: method on the standardUserDefaults instance to do so by passing in a dictionary of key-value pairs.