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

  • 相关阅读:
    mfc启动画面
    个人冲刺第十天
    个人冲刺第九天
    个人冲刺第八天
    个人冲刺第七天
    个人冲刺第六天
    新一周冲刺计划2
    新一周冲刺
    创意1
    团队绩效与目标
  • 原文地址:https://www.cnblogs.com/mobileworld/p/2357159.html
Copyright © 2011-2022 走看看