ios - 我可以在 cordova iOS 应用程序中使用 indexedDB 吗?

标签 ios cordova mobile-safari indexeddb wkwebview

当我尝试在我的 cordova iOS 应用程序中打开索引数据库时,我收到了一个InvalidAccessError

平台:

  • Cordova :5.4.1
  • Cordova -ios:4.0.1
  • iOS 9.2(模拟器和真机)

我已经添加了 Plugin to use the WKWebview这使得至少定义了 indexedDB 对象,但抛出了错误。如果我通过 cordova 自己的网络服务器运行该代码,它可以在 chrome、safari 和移动 safari 中运行。

config.xml 看起来像这样

<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
    <allow-intent href="market:*" />
</platform>
<platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
</platform>
<feature name="CDVWKWebViewEngine">
    <param name="ios-package" value="CDVWKWebViewEngine" />
</feature>

<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />

然后我尝试用这个打开 indexedDB:

openDb: function() {
    var openRequest = window.indexedDB.open(DB_NAME, DB_VERSION);
    openRequest.onupgradeneeded = function(event) {
        console.log('upgrade needed');
        console.log(event);
        myIndexDb = event.target.result;
        var options = {
            autoIncrement: true,
            keyPath: 'key'
        };
        var objectStore = myIndexDb.createObjectStore(DB_STORE_NAME, options);
    };
    openRequest.onerror = function(event) {
        console.log(event);
        console.log('indexDB open Error!');
    };
    openRequest.onsuccess = function(event) {
        console.log('open success');
        myIndexDb = this.result;
    };
    openRequest.onblocked = function(event) {
        console.log('request is blocked');
        console.log(event);
    }
}

最佳答案

目前它与 Telerik 插件一起使用 https://github.com/Telerik-Verified-Plugins/WKWebView (和 cordova-ios 3.9.2)

关于ios - 我可以在 cordova iOS 应用程序中使用 indexedDB 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34616896/

相关文章:

java - 如何让我的 Web 应用程序在移动设备浏览器上使用不同的样式表呈现?

iphone - iPhone 4 Safari 上奇怪的水平空白

ios - 如何在 iOS 中向 UITableViewCell 异步添加 View ?

ios - 发布到 Facebook 的链接,包括应用程序 URL 方案 - iOS 6

ios - swift 提出 Unresolved 标识符

cordova - 在cordova-plugin-splashscreen中更改启动画面微调器的颜色

javascript - jQuery/Cordova 历史问题 - iOS 9 历史被打破?

javascript - 如何使用javascript获取android phonegap中sdcard目录的完整路径?

ios7 - iBeacon 移动网络应用程序开发

iphone - 在 Objective-c 中实现倒数计时器?