Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Deivore

macrumors newbie
Original poster
Jan 8, 2014
3
0
Hello all!

I'm writing an educational game and want to log user actions on a local database since I am not guaranteed internet access at the deployment site.

What I tried initially was to use a database path string as

Code:
dbPathString = [[NSBundle mainBundle] pathForResource:@"Journey" ofType:@"sqlite"];

which wrote to a database file inside the application support files of the program. The program pulled from and pushed to the database and these changes were preserved in Xcode's iPhone Simulator. However, the deployed program on the iPad never seemed to make changes in the respective file on the iPad. I determined this by examining the ipad wih "iPad File Explorer".

Am I doing something wrong here? Is there a better way to write and read from a database local to the iPad?

Thanks!
 
Last edited by a moderator:
Ok, will do. Thanks.

Edit: Looks like I was maybe trying to write to <Application_Home>/AppName.app when I should have written to <Application_Home>/Documents/ , be back soon.
 
Ok, will do. Thanks.

Edit: Looks like I was maybe trying to write to <Application_Home>/AppName.app when I should have written to <Application_Home>/Documents/ , be back soon.

Right. The app bundle is read-only on an iOS device (beware, you CAN write to files in the bundle from the simulator, so it appears to work from the sim.)

What you want to do is write code that checks for an SQL file in your documents directory at launch. If it exists, open it and proceed as normal. Changes to documents will be saved correctly.

If the SQL file does NOT exist, copy it from the bundle into your documents directory. Then fall into the code that opens it in the documents directory.

That way, on first launch, you put the starting database into the documents directory, and after that you use the users updated database.
 
Success!

Wanted to report back, say that this was indeed the problem. Thanks all!
 
You should learn how to use the Core Data framework, because you can easily use it to store data on a device. The advantage of telling the app to cache the data is that the app can use data it retrieved the last time it synchronized the two databases.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.