简体   繁体   中英

Settings.plist iOS

I have a Settings.plist file in my iOS application. I access it using this code below:

    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Settings.plist"];

    NSFileManager *fileManager = [NSFileManager defaultManager];


    if (![fileManager fileExistsAtPath: path])
    {
        NSString *bundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"];

        [fileManager copyItemAtPath:bundle toPath: path error:&error];
    }

    NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path];

But, say I make some changes to the Settings.plist file in my application, like add another row. Then if I publish it, users that already have my app will have an out dated Settings.plist file. Any ideas on a workaround or anything? I have tried accessing the Settings.plist file straight from the NSString *bundle , but then the values don't "save".

You need to do a file modification date check, see my answer here . Then if the modification date is later than the last checked date, download the Settings.plist file and replace it in the users app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM