iPhone read/write .plist file

后端 未结 2 1996
离开以前
离开以前 2020-12-03 19:46

I\'m making a application where I need to store some information the user have provided. I try to use a .plist file to store the information, I found this:

N         


        
2条回答
  •  时光说笑
    2020-12-03 20:07

    Are you using that same path on your device? Apps on a device are sandboxed and can only read/write files in their documents directory. Grab that file path like this and append your plist name. This approach will also work on the simulator.

    Try this:

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

提交回复
热议问题