Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop the HTML 5 database from being deleted, when using Phonegap and iOS 5.1

I am creating a quiz style app for iOS using phonegap. The app allows users to create then take the quizzes.

Currently I am using a HTML 5 database using phonegap APIs to store the test and results data. I am concerned though that the database can now be deleted by iOS 5.1 when the device storage gets full.

Is there anyway to mark the webkit cache folder where the database is stored so that it is never deleted? If this is not possible are there any suggestions for another way to store data that will always be persistent.

like image 994
nicktones Avatar asked Mar 12 '12 14:03

nicktones


2 Answers

Yes, it's a pity that Apple did that in iOS5.1

It's possible to change the location of WebKit data calling a private API. You should be able to set the location to a secure folder like Documents. I did not test this solution yet, but look at this post : How do I enable Local Storage in my WebKit-based application?

Phonegap team is also working on that problem: https://issues.apache.org/jira/browse/CB-330

Antoher way is to use SQLite (same as WebSQL) with a phonegap plugin. That plugin save the database in the Document folder, that mean that the DB is not deleted and is saved by iCloud.

Here is the Native SQLite phonegap plugin : https://github.com/davibe/Phonegap-SQLitePlugin Regarding this plugin, it's a little but slower than WebSQL in some case, and there are some differences between the WebSQL API, but here is an adaptor: https://gist.github.com/2009518

You should also migrate the old WebSQL db file (stored in Library/WebKit or Caches directory) to the Document folder. Here is a code to do that : https://gist.github.com/2009491

And if the data are important, you should save it to a server. I wrote a small lib to synchronize the SQlite DB to a server : https://github.com/orbitaloop/WebSqlSync

like image 97
6 revs, 2 users 86% Avatar answered Sep 29 '22 13:09

6 revs, 2 users 86%


There is a fix for both issues with Webkit storage and iOS 5.1

  1. Storage moved from /Webkit to /Cache
  2. Storage is not adjusted to updated folder structure on an App update under iOS 5.1 (WebKit Bug)

https://issues.apache.org/jira/browse/CB-330

This solution seems to be more safe than just changing the location of Webkit data calling a private API. While the App is running the Webkit storage locations are used. On resuming or terminating all data is backuped to the documents folder. Timestamps ensure that ab old backup cannot overwrite newer storage data (if the app crashes...).

The best: Users that are on an older iOS Version using an App with that fix in it, will not suffer damage lost in case of any iOS updates. Thats why one should not wait...

like image 24
Rene Berlin Avatar answered Sep 29 '22 13:09

Rene Berlin