【问题标题】:Can I use indexedDB in a cordova iOS application?我可以在 cordova iOS 应用程序中使用 indexedDB 吗?
【发布时间】:2016-01-05 16:46:34
【问题描述】:

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

平台:

  • 科尔多瓦:5.4.1
  • cordova-ios:4.0.1
  • iOS 9.2(模拟器和真机)

我已经添加了Plugin to use the WKWebview,它使 indexedDB 对象至少被定义,但是抛出了错误。如果我通过科尔多瓦自己的网络服务器运行该代码,它可以在 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);
    }
}

【问题讨论】:

    标签: ios cordova mobile-safari indexeddb wkwebview


    【解决方案1】:

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

    【讨论】:

    • cordova-ios 4.9.2 不存在。 Telerik 插件还有其他替代方案是您使用cordova-ios 4.0.0 或更高版本stackoverflow.com/questions/32405798/…
    • 这是一个错字 - 我的意思是 cordova-ios 3.9.2 - 链接的 cordova-plugin-wkwebview-engine indexedDB 不起作用
    • 我发现使用 PhoneGap Build 我只能使用 CDWKWebViewEngine 插件,如果我将它作为插件添加到我的 config.xml - stackoverflow.com/questions/35573145/… 但是,到目前为止我还没有成功即使 window.indexedDB 存在,也可以在我的应用程序中调用 window.indexedDB.open()。
    【解决方案2】:

    编辑:

    看起来IndexedDB 的问题已在 iOS 10 上得到修复,并且还添加到了UIWebView

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

    您可以使用wkwebview-engine-localhost 插件来解决添加本地网络服务器的错误。安装插件使用

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

    【讨论】:

    • 请注意,您需要为嵌入式 Web 服务器分配一个固定的 tcp 端口号,否则每次应用程序启动并且嵌入式服务器选择一个新的数据库时,您都会获得一个新的数据库,随机,tcp 端口。
    猜你喜欢
    • 1970-01-01
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多