从设备获取NSUserDefaults plist文件 [英] Get NSUserDefaults plist file from device

查看:81
本文介绍了从设备获取NSUserDefaults plist文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在模拟器上测试我的应用程序时,我喜欢从iPhone Simulator文件夹编辑甚至删除应用程序plist文件(其中包含NSUserDefaults)的功能.在测试时证明这很有用(例如,您的应用在其中存储了词典,但是您更改了用于此数据的模型/键,因此需要删除存储的词典).

When testing my app on the simulator, I like the ability to edit, or even trash the apps plist file (which contains the NSUserDefaults) from the iPhone Simulator folder. This proves useful when testing (e.g. your app stores a dictionary in there, but you change the model/keys that you use for this data, and therefore need to remove the dictionary stored).

是否可以在设备上(对于您自己的应用程序)访问该文件,而无需越狱?

Is it possible to access this file on device (for your own app), without jailbreak?

预先感谢

推荐答案

文件位于Library/Preferences中.该文件是名称为<iOS application target identifier>.plist的二进制plist(在应用程序目标设置中查找Identifier字段),或列出目录内容:

The file is in Library/Preferences. The file is a binary plist with name <iOS application target identifier>.plist (look for the Identifier field in your app target settings), or list the directory contents:

NSString *path = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];

您还可以使用基于某些env变量的#ifdef宏加载干净的默认值:

You could also load clean defaults with a #ifdef macro based on some env variable:

#ifdef TESTING
    // use the code provided by tsakoyan below
#endif

这篇关于从设备获取NSUserDefaults plist文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆