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/
Related
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
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.
So after doing a LOT of research on the web. I figured the best way to ship my app is to ship it with a sqlite db that is generated by coredata application.
Now to go about it I have decide that the following needs to be done:
1) Convert the data into a CSV format
2) Create a Coredata Mac application on my desktop
3) Parse the csv file and feed the contents to the coredata application on my mac and save as sqlite db.
4) Since the coredata model on the mac and iPhone is the same the underlying sqlite db will be compatible.
5) Include the sqlite db that was generated by my mac app with the iphone app.
So the question then is:
To create a mac app where do I start?
So far these are the steps I can think of:
1) Create a Mac app in XCode with Core data
2) create the "schema" on the coredata model that maps to the CSV file data
--??? This is where i get stuck!!
What next ??
Can someone help me please?
I cannot find any resources on the web for this or Im searching with the wrong keywords
Thanks a lot!
I did the exact same thing you wanted except I created a second target in my iPhone app that parses the csv and writes it out to core data. Run it in the simulator, you can find the sqlite file in
/"home"/Libary/Application Support/iPhone Simulator/5.0/Applications/"the app"/Documents
This way everything is kept in one project.
I have done a similar thing. I generated the CoreData db in the app with an #ifdef section that generated the db. That seemed simpler than creating a separate Mac application.
If you need to change the CoreData db in the app just copy it to the Library or Documents directory on initial startup. The only gotcha was that I had to change the db extension in the app so that Xcode would not make changes during compile/archive.
First i would apologize for the question as there are answers out there but as this is my first project i do not really understand the explanations how to do this.
I have an application that uses Core Data, which works on the simulator but not when i generate it on my device. The app starts but it seems like the Core Data is empty. I guess i need to move the DB into the device.
Would someone nice be able to, in a simple way, explain how I fix this?
PROBLEM SOLVED
I downloaded "iPhone Explorer" (http://www.macroplant.com/iphoneexplorer/) and manually removed the two instances of the DB on the actual device and re-run the app and all finally worked.
If you populate the sqlite generated by Core Data (found in the simulator folder) and want to add to the main bundle of your project to load on application startup, then please see the instructions on the following website:
http://iphonedevelopment.blogspot.com/2010/08/core-data-starting-data.html
This basically checks for the pre-populated DB. If not found, it creates one as normally done when on first launch of a application which uses Core Data.
i'm developing an iphone app that uses local Sqlite3 DB; i would like to add an "Update data" menu voice that checks whether a new sqlite db version is found on my site and, if true, downloads file to the device. Data can change very often, so i'm asking if it is possible in some way without passing from the AppStore.
If yes, how can it be implemented?
Thanks in advance.
Grettings !
c.
You can download a sqlite file on app launch and switch it out easily in the code. Of course if the schema changes then thats a bigger problem but if its just data then it should be straightforward.