所以我已经开始使用 NSCoder 构建 plist 文件,但是当我正在开发时,我想查看它们并查看正在保存哪些数据。
我如何在模拟器中查找/访问由我的应用程序生成的 plist 文件(当我到达时在设备上)
我看过的地方:
- 应用程序包
- 构建目录
所以我已经开始使用 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/ 文件夹中。然后,您可以在以下位置找到该文件:~/Library/Application Support/iPhone Simulator/User/Applications/ Application GUID /Documents/
祝你好运。
哇,这很愚蠢,
在 / 找到它们
这个模拟器根本不能很好地模拟真实的手机环境。
如果您的 plist 在 Document 文件夹中,则将路径指定为
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
否则,如果您的 plist 文件位于资源文件夹中,则将资源文件夹的路径指定为
[[NSBundle mainbundle] pathforresources:..........];