Recording PList in Device

1

I'm having trouble writing a Plist in my app. When I test the simulator it works normally, but the device does not save my changes.

I have seen in some sites that I have to create my plist in an accessible place for the device, which is not just create in the project folder and quit using. But I did not quite understand how to do that.

So the question is how do I create a Plist with data in the application and allow the user to change it?

And if anyone can explain the concept to me, I'm grateful.

    
asked by anonymous 01.04.2014 / 02:50

1 answer

1

You need to create this file at run time in the Documents directory, which is where your application is writable as well, as this is the default concept of iOS applications, running in an environment sandbox . That is, creating the file by Xcode , your application will not have such a permission.

For this, you can do something like this when the application is installed:

NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *strPlist = [documentsPath stringByAppendingPathComponent:@"arquivo.plist"];

if (![[NSFileManager defaultManager] fileExistsAtPath:strPlist]) {
    NSArray *arrInfo = /* criar informações da sua plist */;
    [arrInfo writeToFile:strPlist atomically:YES];
}

See if you can get something out of it. To better understand the environment, you can read the guide in the The Sandbox App section.

    
01.04.2014 / 14:35