localForage 使用 WebSQL web IndexedDB 可用

Lon*_*Dev 2 javascript google-chrome indexeddb angularjs localforage

我正在使用 Ionic 框架构建 Cordova 应用程序。我使用angular-localForage作为应用程序持久存储的本地数据库。

在开发过程中,我正在 Windows 10 上使用 Google Chrome 45.0.2454.85 m 测试我的应用程序。angular-localForage 的版本为 1.2.3,localForage 的版本为 1.2.4。

我可以设置和检索数据没问题。要设置我使用的数据:

$localForage.setItem(myKey, myData).then(myCallbackFunction);
Run Code Online (Sandbox Code Playgroud)

根据docs,如果可用,localForage 应该使用 IndexedDB,而对于不可用的浏览器,则回退到 WebSQL。我可以通过查看 Chrome 开发人员工具中的资源看到它正在将我的数据存储在 WebSQL 中。

如果我将此代码放在我的控制器中,我会收到一条消息,指出 IndexedDB 可用:

if (!window.indexedDB) {
    window.alert("Your browser doesn't support a stable version of IndexedDB. Such and such feature will not be available.");
} else {
    window.alert("IndexedDB available.");
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我有 IndexedDB 可用时,为什么它在 Chrome 中使用 WebSQL?

wle*_*300 5

这个问题实际上非常狡猾。

TLDR;Apple 的 UIWebView 不支持 indexedDB。关闭 Chrome 的 iOS 模拟器以查看 indexedDB 的工作情况。

发生的事情是我假设您正在使用 Chrome 开发工具模拟 iPhone。好吧,这种欺骗实际上非常有效,因为localForage如果您将其配置为专门使用 indexedDB,现在会发出错误。

如果您想享受片刻的极度厌倦并看到 indexedDB 的运行...关闭仿真,以便您使用 Chrome 自己的用户代理。到时候就可以了。

来源:我不得不自己处理这些废话。这是一次非常糟糕的开发者体验。哈哈。