iphone - iOS 设置.plist

标签 iphone ios objective-c

我的 iOS 应用程序中有一个 Settings.plist 文件。我使用下面的代码访问它:

    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];

但是,假设我对应用程序中的 Settings.plist 文件进行了一些更改,例如添加另一行。然后,如果我发布它,已经拥有我的应用程序的用户将拥有一个过时的 Settings.plist 文件。关于解决方法或其他任何想法?我尝试直接从 NSString *bundle 访问 Settings.plist 文件,但这些值不会“保存”。

最佳答案

您需要检查文件修改日期,请参阅 my answer here .然后如果修改日期晚于上次检查日期,则下载 Settings.plist 文件并在用户应用程序中替换它。

关于iphone - iOS 设置.plist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19230826/

相关文章:

ios - 可点击的 UILabel

iOS UITableViewCell setSelected :animated: always has animated = NO

objective-c - 在 Objective-C 的函数签名中添加参数

objective-c - 模态视图 Controller 中的 UIWebView

ios - TextEdit 字段输入在 iOS10 上挂起

iphone - UIImageView 设置框架 : not working in UITableViewCell

iphone - 更改 URL 并重新加载 UIWebView?

ios - AVplayer 和视频文件扩展 - 导出和共享管道

ios - 为什么我应该将自定义数据源对象声明为存储属性?

objective-c - 按下按钮后更新 Cocoa/Objective C 中的屏幕