如何在开发过程中测试我的应用程序数据持久性?

时间:2021-09-07 07:25:42

My question is related to the following three questions.

我的问题与以下三个问题有关。

  1. iPhone What happens to previous data when app is upgraded to new version

    当app升级到新版本时,之前的数据会发生什么变化。

  2. How the application upgrade works in iPhone

    应用程序升级在iPhone中如何工作

  3. Preventing erasure of user data while upgrading iOS application via iTunes

    在通过iTunes升级iOS应用程序时防止用户数据被删除

Here are my 2 questions.

这是我的两个问题。

  1. Am I supposed to create a "Documents" directory manually on filesystem or create just a "group" in xcode, so that when app is upgraded, data stay persistant?

    我应该在文件系统上手动创建一个“文档”目录,还是在xcode中只创建一个“组”,以便在应用程序升级时,数据保持持久性?

  2. How I can test the app persistance during the app development on simulator or on IPhone?

    如何在模拟器上或IPhone上测试app的持久性?

Thanks.

谢谢。

3 个解决方案

#1


3  

  1. Neither. The Documents directory is created for you when your app is installed. You can get the path to it using:

    既不。安装应用程序时,将为您创建Documents目录。您可以使用:

    NSString *docuDir = nil;
    NSArray *list = NSSearchPathForDirectoriesInDomains(
            NSDocumentsDirectory, NSUserDomainMask, YES/*expand tilde*/);
    if ([list count]) docuDir = [list objectAtIndex:0U];
    
  2. As @Ben said, the directory is only deleted when you explicitly uninstall the app (delete it from within Springboard). When you build and run, Xcode effectively does an in-place upgrade of your app. If everything is intact then (and there's no reason it wouldn't be), you should be fine.

    正如@Ben所说,只有在显式地卸载应用程序时才会删除该目录(从Springboard中删除它)。当你构建并运行时,Xcode会有效地对你的应用进行就地升级。

#2


1  

When the app is upgraded your Documents folder is left intact. You can copy files into the Documents directory the first time your app is run such as a sqlite file for example, obviously only if it doesn't already exist. If you use CoreData then it will automatically store your data there. You will need to be able to run migration scripts if your data schema changes on upgrade, so keep that in mind. CoreData has migration features to take care of this for you and of course you can do it manually too.

当应用程序升级时,文档文件夹保持原样。您可以在应用程序第一次运行时将文件复制到Documents目录中,例如sqlite文件,显然只有在它还不存在的情况下。如果您使用CoreData,那么它将自动将您的数据存储在那里。如果您的数据模式在升级时发生变化,您需要能够运行迁移脚本,所以请记住这一点。CoreData具有迁移特性,可以为您解决这个问题,当然您也可以手动完成。

When you run an app in the simulator it also leaves the Documents directory intact, so you have to delete the app from the simulator to simulate a fresh install. An upgrade is simulated simply by running your code since the Documents folder was created on the 'fresh install' first run.

当您在模拟器中运行一个应用程序时,它也保留了文档目录,因此您必须从模拟器中删除该应用程序,以模拟新的安装。仅仅通过运行代码就可以模拟升级,因为文档文件夹是在“fresh install”第一次运行时创建的。

#3


1  

Another way to approach this would be look at the Documents folder. If you are running your app in the simulator, then your app's Documents folder will have a path something like this:

另一种方法是查看文档文件夹。如果你在模拟器中运行你的应用程序,那么你的应用程序的文档文件夹就会有这样的路径:

/Users/itsaboutcode/Library/Application Support/iPhone Simulator/4.1/Applications/SOME_LONG_HEX_KEY_THAT_MAPS_TO_YOUR_APP/

/用户/ itsaboutcode /图书馆/应用支持/ iPhone模拟器/ 4.1 /应用程序/ SOME_LONG_HEX_KEY_THAT_MAPS_TO_YOUR_APP /

If you are testing on an iDevice, then use Xcode's Organizer window's Summary tab. At the bottom there's a section called Applications. You app will be near the top of that list and it will have a toggle triangle - which you will click on. This will reveal "Application Data" which can be downloaded by clicking on downward pointing arrow to the right.

如果您正在测试一个iDevice,那么使用Xcode的组织者窗口的Summary选项卡。在底部有一个叫做application的部分。你的应用会在列表的顶部,它会有一个切换三角形——你可以点击它。这将显示“应用程序数据”,可以通过单击右边向下的指向箭头下载。

The iPhone Simulator has the advantage that the Documents folder and its contents can be modified at will. The Application Data on iDevice is read-only (except, of course, for your app at runtime).

iPhone模拟器的优点是可以随意修改文档文件夹及其内容。iDevice上的应用程序数据是只读的(当然,运行时的应用程序除外)。

#1


3  

  1. Neither. The Documents directory is created for you when your app is installed. You can get the path to it using:

    既不。安装应用程序时,将为您创建Documents目录。您可以使用:

    NSString *docuDir = nil;
    NSArray *list = NSSearchPathForDirectoriesInDomains(
            NSDocumentsDirectory, NSUserDomainMask, YES/*expand tilde*/);
    if ([list count]) docuDir = [list objectAtIndex:0U];
    
  2. As @Ben said, the directory is only deleted when you explicitly uninstall the app (delete it from within Springboard). When you build and run, Xcode effectively does an in-place upgrade of your app. If everything is intact then (and there's no reason it wouldn't be), you should be fine.

    正如@Ben所说,只有在显式地卸载应用程序时才会删除该目录(从Springboard中删除它)。当你构建并运行时,Xcode会有效地对你的应用进行就地升级。

#2


1  

When the app is upgraded your Documents folder is left intact. You can copy files into the Documents directory the first time your app is run such as a sqlite file for example, obviously only if it doesn't already exist. If you use CoreData then it will automatically store your data there. You will need to be able to run migration scripts if your data schema changes on upgrade, so keep that in mind. CoreData has migration features to take care of this for you and of course you can do it manually too.

当应用程序升级时,文档文件夹保持原样。您可以在应用程序第一次运行时将文件复制到Documents目录中,例如sqlite文件,显然只有在它还不存在的情况下。如果您使用CoreData,那么它将自动将您的数据存储在那里。如果您的数据模式在升级时发生变化,您需要能够运行迁移脚本,所以请记住这一点。CoreData具有迁移特性,可以为您解决这个问题,当然您也可以手动完成。

When you run an app in the simulator it also leaves the Documents directory intact, so you have to delete the app from the simulator to simulate a fresh install. An upgrade is simulated simply by running your code since the Documents folder was created on the 'fresh install' first run.

当您在模拟器中运行一个应用程序时,它也保留了文档目录,因此您必须从模拟器中删除该应用程序,以模拟新的安装。仅仅通过运行代码就可以模拟升级,因为文档文件夹是在“fresh install”第一次运行时创建的。

#3


1  

Another way to approach this would be look at the Documents folder. If you are running your app in the simulator, then your app's Documents folder will have a path something like this:

另一种方法是查看文档文件夹。如果你在模拟器中运行你的应用程序,那么你的应用程序的文档文件夹就会有这样的路径:

/Users/itsaboutcode/Library/Application Support/iPhone Simulator/4.1/Applications/SOME_LONG_HEX_KEY_THAT_MAPS_TO_YOUR_APP/

/用户/ itsaboutcode /图书馆/应用支持/ iPhone模拟器/ 4.1 /应用程序/ SOME_LONG_HEX_KEY_THAT_MAPS_TO_YOUR_APP /

If you are testing on an iDevice, then use Xcode's Organizer window's Summary tab. At the bottom there's a section called Applications. You app will be near the top of that list and it will have a toggle triangle - which you will click on. This will reveal "Application Data" which can be downloaded by clicking on downward pointing arrow to the right.

如果您正在测试一个iDevice,那么使用Xcode的组织者窗口的Summary选项卡。在底部有一个叫做application的部分。你的应用会在列表的顶部,它会有一个切换三角形——你可以点击它。这将显示“应用程序数据”,可以通过单击右边向下的指向箭头下载。

The iPhone Simulator has the advantage that the Documents folder and its contents can be modified at will. The Application Data on iDevice is read-only (except, of course, for your app at runtime).

iPhone模拟器的优点是可以随意修改文档文件夹及其内容。iDevice上的应用程序数据是只读的(当然,运行时的应用程序除外)。