我可以以编程方式擦除applicationDidFinishLaunching:withOptions:中的应用程序数据吗?

问题描述:

出于测试目的,我希望能够将应用程序重置为干净状态. (类似于从Simulator/iPhone删除应用程序的操作.)

For testing purposes, I'd like to be able to just reset the application to a clean state. (Similar to what deleting the app from the Simulator / iPhone does).

假设我们有一个WIPE_DATA定义,如果已定义,则应用程序应该像刚安装时一样启动.显然,如果您了解该应用程序,就知道它在NSUserDefaults等中存储数据的位置.我想知道是否有一种更通用的方法,不需要深入了解特定应用程序,因此适用于任何应用程序.

Assume we have a WIPE_DATA define, if that is set, the app should start as if it has been just installed. Obviously if you know the app, you know where it stores data in NSUserDefaults etc. I was wondering if there was a more generic approach that requires no insight into the specific app and thus would be applicable to any app.

在您的应用中,您有两种数据-NSUserDefaults设置和Documents目录中的文件.如果您要擦除所有数据以使您的应用程序进入初始状态和设置,则应创建例如一个应用程序委托方法,该方法可以设置初始NSUserDefaults设置并清除文档"目录中的应用程序生成的文件.

In your app you have two kinds of data - NSUserDefaults settings and files in Documents directory. If you want to wipe all the data to make your application to initial state and settings, you should create e.g. an app delegate method which set initial NSUserDefaults settings and clean application generated files in Documents directory.

据我所知,没有标准的方法可以做到这一点.

As far as I know there is no standart system way to do that.