开发者

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

开发者 https://www.devze.com 2022-12-20 14:28 出处:网络
Suppose we are doing a big change and require user to run some migration code from version 1.0 to 2.0. The migration will make changes to data in userdefaults, files and other persistence methods. Wha

Suppose we are doing a big change and require user to run some migration code from version 1.0 to 2.0. The migration will make changes to data in userdefaults, files and other persistence methods. 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 mul开发者_如何学Gotiple test on our migration code?

I know in xcode's organizer, you can expand an app in your device and press the export button. 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). I presume you know this, but you'll find the home directory for you app when run in simulator at:

/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. I just did exactly that (transferring something from 3.1.3 over to the 3.1.3 app) ten minutes ago.

Other alternatives I've considered in the past include:

  • Zip and attach to email the Documents directory.
  • Use an HTTP file upload for a data file or zipped set of files, and http download to reinstate files.
  • More work, but you can also use the Google Docs API (sdk available) to exchange files with a Docs account.


You can export any text to email by launching mailto: URL form your app (use HTML encoding + URL encoding on the body of the message) and later import form email by implementing custom URL handler.


We use NSURLConnection to HTTP POST to and HTTP GET the data from a private web site. It's silly, but works.

0

精彩评论

暂无评论...
验证码 换一张
取 消