在 iPhone 模拟器上访问 plist
-
22-08-2019 - |
题
所以我开始使用 NSCoder 构建 plist 文件,但在开发时我想查看它们并查看正在保存哪些数据。
我如何在模拟器中(以及当我到达时在设备上)找到/访问我的应用程序生成的 plist 文件
我看过的地方:
- 应用程序包
- 构建目录
解决方案
要将它们放入 ~/Library/Application Support/iPhone Simulator/User/Applications/ 子文件夹(如果它们位于真实设备上,它们最终会出现在该子文件夹中),您可以在应用程序中使用以下代码:
+ (NSString *)dataFilePath:(NSString *)filename {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:filename];
}
这会将文件放入应用程序沙箱的 /Documents/ 文件夹中。然后您可以在以下位置找到该文件:〜/库/应用程序支持/iPhone模拟器/用户/应用程序/ 应用程序GUID /文件/
祝你好运。
其他提示
哇,这太蠢了,
找到他们在/
这个模拟器根本不能很好地模拟真实的手机环境。
如果您的 plist 位于 Document 文件夹中,则将路径指定为
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
否则,如果您的 plist 文件位于资源文件夹中,则将资源文件夹的路径指定为
[[NSBundle mainbundle] pathforresources:..........];
不隶属于 StackOverflow