Recording Plist on Device

Asked

Viewed 206 times

1

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

I saw on some websites that I have to create my plist in an accessible place for the device, which is not just create in the project folder and exit using. But I didn’t quite understand how to do it.

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

And in case anyone can explain to me the concept of that I’m also grateful.

1 answer

1


You need to create this file at runtime in the directory Documents, which is where your app has write permission as well, as this is the default concept of the app on iOS, running in an environment sandbox. That is, create the archive by Xcode, your application will not have such permission.

For this, you can do something more or less 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 anything out of it. To better understand the environment, you can read on programming guide, in the section The App Sandbox.

  • Do I need to enable something for this? When I try to do the reading do not think... read behind the Plist I created in the project...

  • 1

    It worked... I was putting NSDocumentationDirectory instead of NSDocumentDiretory...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.