How can I reset the NSUserDefaults data in the iPhone simulator?(如何在 iPhone 模拟器中重置 NSUserDefaults 数据?)
问题描述
我已将 NSUserDefaults
数据检索添加到我的应用程序中,这非常好.但为了测试,我想重置我添加到默认数据库的所有数据,以便用户第一次启动应用程序时一切都处于状态.
I've added NSUserDefaults
data retrieval to my app, which is pretty nice. But for testing I would like to reset all the data I added to the defaults database, so that everything is in the state when the user launches the app the first time.
我试着打电话:
[NSUserDefaults resetStandardUserDefaults];
但这并没有做任何事情.默认值仍会保存并可以检索.
but that doesn't do anything. The defaults are still saved and can be retrieved.
推荐答案
最简单的方法是从模拟器中删除应用程序 - 就像您从真实手机中删除它一样,通过点击(单击)并按住直到图标开始振动.这会删除所有应用数据,下次您从 Xcode 安装时就像第一次一样.
The easiest way is to remove the app from the simulator-- just like you'd remove it from a real phone, by tapping (clicking) and holding until the icons start vibrating. That removes all app data, and the next time you install from Xcode it's like the first time.
如果您还有其他需要保留的应用数据,您有多种选择.
If you have other app data you need to keep, you have a couple of options.
一种方法是在每个默认键上设置一些调用 removeObjectForKey: 的调试代码.
One way would be to have some debug code that calls removeObjectForKey: on each of your defaults keys.
另一种是找到安装模拟器副本的目录,并删除包含首选项的文件.使用它来查找应用程序:
The other is to find the directory where the simulator copy is installed, and remove the file containing the preferences. Use this to find the app:
ls -ld ~/Library/Application Support/iPhone Simulator/User/Applications/*/*.app
应用程序的完整路径将包含名称为 UUID 的目录.在该目录中,在 Library/Preferences 中查找首选项文件.删除它,用户偏好就消失了.
The full path to your app will contain directory whose name is a UUID. In that directory, look in Library/Preferences for the preferences file. Remove that, and user preferences are gone.
这篇关于如何在 iPhone 模拟器中重置 NSUserDefaults 数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iPhone 模拟器中重置 NSUserDefaults 数据?
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01