Is it possible to view data stored in Core Data on a development iphone? - iphone

Is there a way to grab/view the coredata db (sqlite store) off of the development iphone through xcode or some other means? While I've been able to inspect the db created through the simulator on my mac, I'd like to validate what's on the actual phone (without having to create debugging views in the app, etc.) as i'm reading sensor data and storing it in coredata.

Yes you can using Xcode organizer.
Select you phone, then app, and you can export and import files from/to the sandbox
http://developer.apple.com/library/ios/recipes/xcode_help-devices_organizer/articles/copy_app_data_from_sandbox.html#//apple_ref/doc/uid/TP40010392-CH14-SW1

I'm not sure if there is an official way to do this but I use a piece of software called iExplorer formerly iPhone Explorer. http://www.macroplant.com/iexplorer/
You can then browse the Apps directory similar to the simulator and find your app and goto the documents directory and grab the sqlite file.
Hope this helps

Related

How to safely upgrade/backup an existing app that uses core data?

I have an app that I've built a few months ago and would like to continue upgrading that app.
Since that time, the app has about 6 months of data, and I would like to backup the state of this app before working on upgrading the app (I'm afraid that I will somehow delete/mess up the core data persistent storage if I install a new version of the app.) I do not remember if I got the app from the iTunes store or xCode installation.
I've backed up my iPhone using iTunes and am currently working with an app which has a different app identifier from the production app:
The live app with data I want to save is called "app"
The work in progress version of the app is called "app_test"
There are two versions of the app on the device.
I would like to see how my changes that I've created for the app_test would look on the live production app with real data.
What steps do I need to take to ensure that I can recover my app's data if something goes wrong?
Is it enough for me to change the xcode's project bundle id from "app_test" to "app" to see changes in production?
Thank you for your input, I really value that data and do not want to lose it!
First important point - do not change your "app_test bundle" identifier to "app" - this will overwrite your live app on the phone, and your data will be gone (well, you'll have to restore from backup at least...)
You should be able to use an OSX program such as 'iPhone Explorer' to browse your connected phone - find your app, and see if you can nab the .sqlite file (maybe in the documents or libray folder of your app) - copy it to your desktop.
Now you've got your live database, you have several choices. You could also nab the app_test database, and merge the contents using your favourite sql tools - or import the live .sqlite file to your app_test xcode project, and tell app_test to use that as the data source.
If you need write access to the database, you'll have to copy the live .sqlite from your app_test bundle to the documents or library folder first.

Are there any tools for browsing iCloud data of your app?

I am working on integrating iCloud in my app and sometimes having problems with conflicts and save errors. The fact that the data is stored on the cloud makes it very hard to debug the problems.
As far as I know, the data on the iCloud servers are mirrored to a directory on the device. Is there any tool (an iOS or OSX app) that will allow me to see the contents of this directory or the files in the iCloud servers? I know that it is possible to query the files in the directory with NSMetadataQuery class. However, I am looking for a built-in tool from Apple or an open source application that I can use with my own entitlements.
So far I have tried the following tools with no luck:
On Mac OS X Lion, System Pereferences >> iCloud >> Manage: This only displays the name and size of the documents. It does not allow me to download or see the content.
On iOS 5, Settings >> iCloud >> Storage & Backup >> Manage Storage: Same as above.
On Xcode 4.3.2, Organizer >> Devices >> >> Applications >> Download: This allows me to download the application data but it does not contain the iCloud data.
I have also tried browsing the phone with iPhone Explorer application but it does not display the contents of /private/var which is where the iCloud data is stored.
...or visit http://developer.icloud.com to see what is actually stored in the cloud on Apple's servers...
I found the answer to my question in this answer.
It turns out the data on the cloud is automatically downloaded to my mac under "~/Library/Mobile Documents" folder if I enable "Document & Data" in iCloud Settings page and install a Mac app that is using iCloud.
Currently there is no documented way to view native iCloud data. However, depending on what your data is, you might be able to view it under some circumstances. For example, iCloud can be used to sync databases that are accessed via CoreData. If you store your data in a Sqlite database, which is then managed and accessed via CoreData, you can use 3rd party desktop apps to view the Sqlite file. I use this tool to view my Sqlite databases on a Mac: http://www.sqlabs.net/sqlitemanager.php

How do I download an sqlite database from an app on my iPhone?

I made an iPhone app that allows data entry. Over the past month I have been using it and input a lot of data that is now only on my iPhone in the sqlite database used by the app. I want to get the data off my phone now and store it somewhere else.
Is there anyway to access the sqlite database on the iPhone? If so can this data be updated externally or would the database need to be "re-embedded" and copied back over to the iPhone at build?
Try the iPhone Backup Extractor.
http://www.iphonebackupextractor.com/
If it is a development version, you can download data in Xcode. Plug in your device and find it in the area you do provisioning. Look for your app icon and there's a download button.

How to transfer Core Data store from provisioned iPhone to iPhone simulator?

I have a lot of data stored in my app on my provisioned device, and I want to do additional testing on my computer which is much faster than using the device. What is the best way to transfer the data store into the iPhone simulator so I can access it on the computer?
I think that you can download the data from your device in the Organizer in Xcode.
Once you unzip that folder you should be able to find your sqlite database file.
Now look for the folder on your hard drive where the simulator keeps its files. I think it's somewhere in ~/Library/Application Support/iPhone Simulator or something like that. There should be a folder for each app somewhere in there (the folder name will be some random ID), and you should be able to find an sqlite database with the same name. Replace that database with the one you downloaded from the device.
Sorry I can't give more detailed instructions. I'm at work currently and don't have access to my Macbook to get the exact folder names and such.

Connecting CoreData to my App on an iPhone Device

I apologize ahead of time for what I'm sure is a complete newbie lapse. Running my iPhone app on iPhone simulator - no problem. But I loaded the app on an iPhone device for the first time and it appears as if the SQLite database I'm using (NSManagedObjectContext) isn't connected or didn't upload. The app installs but with no data. How do I get it all to upload and work on the device?
I appreciate any help.
lq
The first rule with Core Data is that you should never ever touch the store directly. It should be considered a black box and only accessed via the the Core Data APIs. Accessing the database directly is unsupported and can lead to data corruption.
What you should do instead is create a trivial desktop application (or command line is you are just importing from another source) and enter the data there. Once the data is entered then copy the sqlite file to your mobile application and include it in the bundle. That way you are accessing the file from Core Data. Since Apple can and does change the structure of that file without notice your application will be future proof.
update
If you have created a database using Core Data you can then take that sqlite file and add it to your Xcode project for your iPhone application. Xcode will then copy it into the app bundle when it compiles the project.
Looking a little deeper I found a link that answers my own question. So anyone with the same question, this solved the issue for me:
http://ablogontech.wordpress.com/2009/07/13/using-a-pre-populated-sqlite-database-with-core-data-on-iphone-os-3-0/