Ok, yesterday I got the backup working and it does work, but I spent a good deal of time last night and this morning trying to get the restore to work. I see the backup copy under ~/Library/Application Support/iPhone Simulator/3.1/Applications/app_id/Documents/appBackup.db
var failedFile = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'app.db'); Ti.API.info('failedFile is ' + failedFile); failedFile.deleteFile(); var restoreDir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory); Ti.API.info('failedFile is ' + failedFile); var restoreFile = Titanium.Filesystem.getFile(restoreDir.nativePath, 'appBackup.db'); Ti.API.info('restoreFile is ' + restoreFile + ' just name is ' + restoreFile.name); Ti.API.info('restoreFile writeable? = ' + restoreFile.writeable); failedFile.write(restoreFile.read());
This simple code should do the trick, but it seems I can't write to failedFile in this example which is in resourcesDirectory:
[INFO] restoreFile writeable? = false
…but I can delete the file
I did a find in the iPhone Simulator directory for app.db and did not find a copy there…
So, it doesn't look like the database is copied from resourcesDirectory, but when changes are made - I don't see them in app.db in that directory. Where is my data file?
And to top it off, the data persists but when I use sqlite3 to open the database in the resourcesDirectory I don't see the changes…
despite the fact that applicationSupportDirectory/database/app_data.sql tells me that it is no writeable, I was able to write to it. I've tested and my database restores properly!
Nice work Eric! :)