zoukankan      html  css  js  c++  java
  • 关于Plist文件的读写

    Plist文件的读取

    NSString *path = [[NSBundle mainBundle] pathForResource:@"myPlist" ofType:@"plist"];   
    NSMutableDictionary *myDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path];

    Plist文件的写入

    [myDictionary writeToFile:path atomically:YES];

    这样做在模拟器上运行是没有任何问题的,但是在真机当中,你就会发现只能读取不能写入,原因是在真机上,自己包里的文件,不管你是否plist还是.jpg等,都只能读,如果要写就要拷贝到安装后的doc目录下.  

    解决方案是:

    修改文件的路径即可

    NSArray *storeFilePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *doucumentsDirectiory = [storeFilePath objectAtIndex:0];
    NSString *path=[doucumentsDirectiory stringByAppendingPathComponent:@"myPlist.plist"];

    修改前:

    /var/mobile/Applications/A528A4DE-F391-4247-8C5D-9386DC415A00/Box.app/myPlist.plist

    修改后:

    /var/mobile/Applications/A528A4DE-F391-4247-8C5D-9386DC415A00/Documents/myPlist.plist

  • 相关阅读:
    EcFinal游记
    简要介绍补码的原理
    【SCOI2007】降雨量
    【ecfinal2019热身赛】B题
    【HAOI2011】problem a
    20200301(ABC)题解 by李旭晨
    20200228(ABC)题解 by 马鸿儒
    20200220(C)题解 b刘存
    20200225(DEF)题解 by 马鸿儒
    20200224(ABC)题解 by 马鸿儒
  • 原文地址:https://www.cnblogs.com/mobileworld/p/2357159.html
Copyright © 2011-2022 走看看