PhoneGap 3.0 - 无法调用undefined方法'confirm'

时间:2013-12-02 20:56:23

标签: android cordova confirm

我正在尝试调用phonegap的方法navigator.notification.confirm,但我只收到错误Cannot call method 'confirm' of undefined

我添加了必要的插件:

phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration.git
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git

和权限:

// in www\config.xml
<feature name="Notification">
    <param name="android-package" value="org.apache.cordova.Notification" />
</feature>

// in platforms\android\AndroidManifest.xml
<uses-permission android:name="android.permission.VIBRATE" />

我的代码是:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
    <script type="text/javascript" charset="utf-8">
      document.addEventListener("deviceready", onDeviceReady, false);

      function onDeviceReady() {}

      function onConfirm(buttonIndex) {
          alert('You selected button ' + buttonIndex);
      }

      function showConfirm() {
        try {
          navigator.notification.confirm(
            'You are the winner!',
            onConfirm,
            'Game Over',
            'Restart,Exit'
          );
        } catch(e) {
          alert('Exception: ' + e.message);
        }
      }
    </script>
  </head>
  <body onLoad="showConfirm();"></body>
</html>

我错过了什么?

1 个答案:

答案 0 :(得分:1)

问题解决了。

我必须删除插件并通过phonegap命令行实用程序再次添加...