BuySellAds.com

Our DNA is written in Objective-C
Jump

Transfer App Data Back to Your Mac

If you are saving data in your apps then you are saving them to your app’s sandboxed documents directory. In simulator files you can easily inspect the contents of the directory if you just browse there with finder or cd there in terminal. Note that there is a space in the path, so you need to put exclamation marks around it if you use it with cd in terminal.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(documentsDirectory);  // output documents directory to debug console

Copy this path, open terminal and go:

MacDrops:~ Oliver$ cd "/Users/Oliver/Library/Application Support/iPhone Simulator/User/Applications/AAC8D0E8-C134-4A94-ACA9-88C7A58DCE1C/Documents"

Or if you prefer Finder then use the handy option “Go To Folder …” and paste the path there. Bear in mind that with every new build the documents directory gets moved to a new application ID. The contents will persist, but the path changes. If you navigate to the ../User/Applications folder you will find that the newest directory is the one that belongs to your just-built app.

There are some rare cases though when you find that Simulator behaves differently than a device. How can you inspect the files there?

Fortunately you don’t have to jailbreak your iPhone just to be able to retrieve the contents of your app’s doc dir. This functionality is there, but Apple hid so well in XCode that you’ll never find it unless somebody points your nose right at it. Like I am doing now.

Connect your development device and go to the XCode Organizer window. Select your device with the green light and then expand the triangle next to your app’s name under “Applications”. There pops up a line “Application Data” with an even smaller downward arrow on the right side. Guess what, that icon is meant to symbolize DOWN-load!

Transfer Data via Organizer

If you click on this you can select a place to put the files. Once the files are saved you also see them appear in the upper left hand corner under “Projects & Sources”. They are sorted by the full bundle identifier of your app suffixed with date and time of the transfer. This way you can keep multiple snapshots and inspect how your written files have changed over time.

One less reason to jailbreak your iPhone. ;-)


Categories: Tools

%d bloggers like this: