在我的应用程序中,我将一些用户数据存储在两个已经包含一些数据的 .plist 文件中,但用户可以更改它。
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"Settings.plist"];
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] initWithContentsOfFile:DataPath];
它可以在模拟器上运行,但不能在设备上运行。
你能帮帮我吗?
谢谢!
最佳答案
您无法写入设备上的包,因此您需要获取您的文档或库目录的路径。
- (NSString*)applicationDocumentsDirectory
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [paths lastObject];
}
关于iphone - 读/写 plist 的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3953092/