开发者

Safely storing data in a HTML5 iOS application - are localStorage / WebSQL / IndexedDB appropriate?

开发者 https://www.devze.com 2023-04-11 06:37 出处:网络
I\'m writing a HTML5 application that I want to release on the iOS app store. Either using PhoneGap or wrapped in a UIWebView control.

I'm writing a HTML5 application that I want to release on the iOS app store. Either using PhoneGap or wrapped in a UIWebView control.

I'm a bit confused about what options I have in terms of storing data for my application.

Are using localStorage, WebSQL or IndexedDB technologies appropriate for storing application data in this type of application? I will be storing JSON and XML data.

Keep in mind, if the user inadvertently deletes this data then they will have lost their work, which obviously I don't want to happen.

I understand that the only real way to alleviate this risk is to sync the data to the "cloud" or other online system - I can do that in a future release, but not right now. Initially I just want to store the data locally if that is a reasonable stable way to do things.

From what I understand, when clearing the cookies the browser will also clear any localStorage data. So that rules that out, as I can see users doing that by accident.

WebSQL looks pretty good - the user can't inadvertently开发者_如何学Python delete it on iOS. They would actually have to go into the browser settings and delete the database manually.

But the downside of WebSQL is that it may not be supported in the future from what I've read.

With IndexedDB, I am not clear when that data gets cleared. Will it also removed when cookies are deleted, or does the "databases" option in the Safari settings control this?

Is IndexedDB the better solution, as it will have better support than WebSQL in the future?

Are there other solutions that are more appropriate that I am not aware of?


If you are wrapping in PhoneGap (or AppMobi - where I work), you're data is segmented to that app. A user can not go into Safari and clear the browser data/cookies and have that happen in your app. The only way they can delete it is by deleting the app.

I don't think IndexedDB is avaiable. Window.localStorage is (5 megs but I think it can grow), which is a KVP system.

I don't see them dropping WebSQL for a few years. The HTML5 spec isn't even ratified yet, so things could change again.

Since you are just storing strings, you can check out libraries like Lawnchair that will use different adapters (localStorage, WebSQL, etc) to store your data how you want since it appears you do not have complex data sets.


localStorage (aka Web Storage) and WebSQL are supported on all current mobile browsers except Opera Mini.

WebSQL, however, is considered "dead" as of November, 2010. The spec has a big fat "beware" label on it. It reads:

This document was on the W3C Recommendation track but specification work has stopped. The specification reached an impasse: all interested implementors have used the same SQL backend (Sqlite), but we need multiple independent implementations to proceed along a standardisation path.

As far as mobile browsers, IndexedDB is -- as of Dec. 2013 -- only supported in Android 4.4 (meaning no iOS Safari, Opera Mini/mobile or widespread Android Browser support).

See caniuse.com for the latest compatibility tables.

0

精彩评论

暂无评论...
验证码 换一张
取 消