2

我刚刚将一个项目从 Cordova 2.6 升级到 2.7,因为 Android 上的 localstorage 2.6 中有一个错误。现在,在页面加载时,我以 3 种略有不同的方式呈现了这一点:

在此处输入图像描述

如果我单击“确定”,页面就会崩溃。看来它来自这个:

module.exports = {
  exec: function(service, action, callbackId, argsJson) {
    return prompt(argsJson, 'gap:'+JSON.stringify([service, action, callbackId]));
  },
  setNativeToJsBridgeMode: function(value) {
    prompt(value, 'gap_bridge_mode:');
  },
  retrieveJsMessages: function() {
    return prompt('', 'gap_poll:');
  }
};

我怎样才能防止这种情况发生?

编辑:它似乎不会发生在 Android 本身上,但它确实发生在 Chrome 中,并且此应用程序在两者中都适用。

4

1 回答 1

0

I don't think you should include the Cordova script in your Chrome only distribution. This alert is popping up because internally Cordova for Android uses the alert() mechanism to pass events between the JavaScript and Native code portions of a Cordova app. I'm pretty sure that when you view the app through Chrome, the rest of Cordova never really gets set up (the native portions), so the alert is not captured and instead is actually surfaced to the Chrome browser.

If the application you are developing works in both Chrome and Android (I'm assuming you are packaging it via Cordova into a native .apk?), I'm having a hard time understanding what you are using Cordova for... If you are not using any of the native device functionality that Cordova provides (Camera access, accelerometer, etc.) and are just using it to wrap a web app in a native shell, you might find it easier to just develop (for Chrome) and release the web app as...well, a web app.

Although I do think one of the major benefits of Cordova is much greater distribution potential in the form of native applications. If this is what you are planning on doing, then I'd say just ignore the alert while you test on Chrome. If you plan to release native apps (via Cordova) and the web app, just remove the Cordova script from the production version of the web app.

于 2013-09-06T15:38:45.043 回答