zoukankan      html  css  js  c++  java
  • plist文件真机写入方法

    http://blog.csdn.net/mydo/article/details/50290219  转

    但是这对真机不管用,因为在真机环境下,App在Xcode中的Resources文件夹都是不可写的.所以我们要在App第一次运行时将需要修改且长久保存的数据放到Document目录下:

    //在Document目录中初始化地图数据文件,因为该目录下文件可写且可以持久保存
    +(void)initDataFile{
        NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,
                                                                YES)[0];
        //取得目标文件路径
        sMapInfoInDocPath = [docPath stringByAppendingPathComponent:@"MapInfo.plist"];
        NSFileManager *fm = [NSFileManager defaultManager];
        //如果目标文件不存在说明是App第一次运行,需要将相关可修改数据文件拷贝至目标路径.
        if (![fm fileExistsAtPath:sMapInfoInDocPath]) {
            NSError *error = nil;
            //取得源文件路径
            NSString *srcPath = [[NSBundle mainBundle] pathForResource:MAP_INFO_FILE ofType:@"plist"];
            if (![fm copyItemAtPath:srcPath toPath:sMapInfoInDocPath error:&error]) {
                CCLOG(@"ERR:copy file failed:%@",error);
            }
        }
    }

    注意当删除一个App后,该App先前存放在Document目录下的所有文件都会被删除.

  • 相关阅读:
    Http系列目录
    C# 锁系列目录
    RabbitMQ系列目录
    Zookeeper系列目录
    Spring Boot系列目录
    SOAP系列目录
    DynamicProxy系列目录
    网络通信系列目录
    分析windows .net程序dump文件的两种方式
    Code Review Checklist
  • 原文地址:https://www.cnblogs.com/yeng/p/5907917.html
Copyright © 2011-2022 走看看