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

时间:2016-01-05 16:46:34

标签: 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和mobile 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);
    }
}

2 个答案:

答案 0 :(得分:1)

目前它适用于Telerik Plugin https://github.com/Telerik-Verified-Plugins/WKWebView(和cordova-ios 3.9.2)

答案 1 :(得分:1)

编辑:

似乎在iOS 10上修复了IndexedDB个问题,并将其添加到UIWebView

老答案: 使用cordova-plugin-wkwebview-engine和IndexedDB解决问题的方法是使用本地Web服务器。

您可以使用wkwebview-engine-localhost插件解决添加本地网络服务器的问题。要安装插件,请使用

cordova plugin add https://github.com/apache/cordova-plugins/tree/master/wkwebview-engine-localhost
相关问题