在 HTML5 iOS 应用程序中安全存储数据 - localStorage / WebSQL / IndexedDB 合适吗?

发布于 2024-12-08 10:44:08 字数 684 浏览 1 评论 0原文

我正在编写一个 HTML5 应用程序,我想在 iOS 应用商店上发布它。使用 PhoneGap 或包装在 UIWebView 控件中。

我对为应用程序存储数据有哪些选项感到有点困惑。

使用 localStorage、WebSQL 或 IndexedDB 技术是否适合在此类应用程序中存储应用程序数据?我将存储 JSON 和 XML 数据。

请记住,如果用户无意中删除了这些数据,那么他们将丢失他们的工作,这显然是我不希望发生的。

我知道减轻这种风险的唯一真正方法是将数据同步到“云”或其他在线系统 - 我可以在未来的版本中做到这一点,但现在不行。最初,我只想在本地存储数据(如果这是一种合理稳定的做事方式)。

据我了解,清除 cookie 时,浏览器也会清除所有本地存储数据。所以这就排除了这种可能性,因为我可以看到用户偶然这样做。

WebSQL 看起来相当不错 - 用户无法在 iOS 上无意中删除它。他们实际上必须进入浏览器设置并手动删除数据库。

但据我了解,WebSQL 的缺点是将来可能不再支持它。

对于 IndexedDB,我不清楚数据何时被清除。当 cookie 被删除时,它也会被删除吗?还是 Safari 设置中的“数据库”选项可以控制这一点?

IndexedDB 是否是更好的解决方案,因为它将来会比 WebSQL 提供更好的支持?

还有其他我不知道的更合适的解决方案吗?

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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初心 2024-12-15 10:44:08

如果您使用 PhoneGap(或 AppMobi - 我工作的地方)进行包装,您的数据将被分段到该应用程序。用户无法进入 Safari 并清除浏览器数据/cookie,并在您的应用程序中发生这种情况。他们删除它的唯一方法是删除该应用程序。

我认为 IndexedDB 不可用。 Window.localStorage 是(5兆,但我认为它可以增长),这是一个KVP系统。

我认为他们几年内都不会放弃 WebSQL。 HTML5 规范尚未获得批准,因此情况可能会再次发生变化。

由于您只是存储字符串,因此您可以查看 Lawnchair 等库,它们将使用不同的适配器(localStorage、WebSQL 等)来存储您想要的数据,因为您似乎没有复杂的数据集。

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.

注定孤独终老 2024-12-15 10:44:08

除了 Opera Mini 之外,当前所有移动浏览器均支持 localStorage(又名 Web Storage)和 WebSQL。

然而,截至 2010 年 11 月,WebSQL 被认为“已死”。该规范上有一个很大的“小心”标签。 内容如下

该文档位于 W3C 推荐轨道上,但规范工作已停止。该规范陷入了僵局:
所有感兴趣的实现者都使用相同的 SQL 后端 (Sqlite),
但我们需要多个独立的实现来沿着
标准化路径。

就移动浏览器而言,截至 2013 年 12 月,IndexedDB 仅在 Android 4.4 中受支持(意味着不支持 iOS Safari、Opera Mini/移动或广泛的 Android 浏览器)。

请参阅 caniuse.com 了解最新的兼容性表。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文