简体   繁体   English

有没有办法保存iPhone应用程序数据(导出它并稍后导入进行测试?)

[英]Is there a way to save iPhone app data (export it and import later for testing?)

Suppose we are doing a big change and require user to run some migration code from version 1.0 to 2.0. 假设我们正在进行大的更改,并要求用户从1.0版到2.0版运行一些迁移代码。 The migration will make changes to data in userdefaults, files and other persistence methods. 迁移将更改userdefaults,文件和其他持久性方法中的数据。 What is a good way to just export all the app specific data (in the device or simulator) and be able to import it back later so we can run multiple test on our migration code? 有什么好方法可以导出所有应用程序特定数据(在设备或模拟器中)并能够稍后导回它,以便我们可以对我们的迁移代码进行多次测试?

I know in xcode's organizer, you can expand an app in your device and press the export button. 我知道在xcode的组织者中,您可以在设备中展开应用程序并按导出按钮。 This seems like the exact thing I need but I couldn't find an import button. 这似乎是我需要的确切的东西,但我找不到导入按钮。

Any ideas? 有任何想法吗?

In simulator, just copy your Documents folder somewhere else (or an item from it, if that's all you need). 在模拟器中,只需将您的Documents文件夹复制到其他地方(或者从中获取一个项目,如果这就是您需要的全部内容)。 I presume you know this, but you'll find the home directory for you app when run in simulator at: 我认为你知道这一点,但是当你在模拟器中运行时,你会找到你app的主目录:

/Users/<you>/Library/Application Support/iPhone Simulator/3.1.3/Applications
/Users/<you>/Library/Application Support/iPhone Simulator/3.1.2/Applications

etc. 等等

Before launching again in simulator if you want to restore the data files, drag them into the current app/sim folder. 如果要恢复数据文件,请在模拟器中再次启动之前,将它们拖到当前的app / sim文件夹中。 I just did exactly that (transferring something from 3.1.3 over to the 3.1.3 app) ten minutes ago. 十分钟前我就是这样做的(将一些东西从3.1.3转移到3.1.3应用程序)。

Other alternatives I've considered in the past include: 我过去考虑过的其他替代方案包括:

  • Zip and attach to email the Documents directory. 压缩并附加到Documents目录的电子邮件。
  • Use an HTTP file upload for a data file or zipped set of files, and http download to reinstate files. 对数据文件或压缩文件集使用HTTP文件上载,使用http下载恢复文件。
  • More work, but you can also use the Google Docs API ( sdk available ) to exchange files with a Docs account. 更多工作,但您也可以使用Google文档API( 可用的sdk )与文档帐户交换文件。

您可以通过从您的应用程序启动mailto:URL(在邮件正文中使用HTML编码+ URL编码),然后通过实现自定义URL处理程序导入表单电子邮件,将任何文本导出到电子邮件。

We use NSURLConnection to HTTP POST to and HTTP GET the data from a private web site. 我们使用NSURLConnection来HTTP POST和HTTP GET来自私人网站的数据。 It's silly, but works. 这很愚蠢,但很有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM