PhoneGap Notification.Alert不起作用

好吧,我一直在这个问题上工作了一段时间,不能把这件事情弄清楚。 简单的PhoneGaptesting应用程序,试图显示一个提醒。

使用cordova2.9.0的iOS 。 我已经添加了一些简单的testing代码,并在chrome中testing它,以查看它在哪里中断,因为它不在模拟器中工作

当我在Chrome中testing(当然模拟器的结果相同,但没有显示错误信息)

  • 它执行onDeviceReady,因为它应该
  • 它将tb2文本框的值设置为“alert”之前
  • 然后它打破了错误:Uncaught TypeError:不能调用未定义的方法“警报”,在这一行:navigator.notification.alert(…

它应该正确引用cordova.js,这里是我的应用程序文件夹的结构:

  • cordova_plugins.js
  • cordova.js
  • /规格
  • spec.html
  • config.xml中
  • / CSS
  • home.html的
  • / IMG
  • 的index.html
  • / JS
  • / RES

这是我的config.xml代码:

<?xml version='1.0' encoding='utf-8'?> <widget id="com.blahblahblah.hello" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> <name>Hello World</name> <description> Test blahblahblah Application </description> <author email="blahblahblah@blahblahblah.com" href="http://blahblahblah.com"> blahblahblah </author> <access origin="*" /> <preference name="fullscreen" value="true" /> <preference name="webviewbounce" value="true" /> <plugins> <plugin name="Notification" value="CDVNotification" /> </plugins> </widget> 

这是我的index.html代码:

 <!DOCTYPE html> <html> <head> <title>Notification Example</title> <script type="text/javascript" charset="utf-8" src="cordova.js"></script> <script type="text/javascript" charset="utf-8"> // Wait for Cordova to load // document.addEventListener("deviceready", onDeviceReady, false); // Cordova is ready // function onDeviceReady() { // Empty document.getElementById('tb1').value = 'device ready'; } // alert dialog dismissed function alertDismissed() { // do something } // Show a custom alert // function showAlert() { document.getElementById('tb2').value = 'before alert'; navigator.notification.alert( 'You are the winner!', // message alertDismissed, // callback 'Game Over', // title 'Done' // buttonName ); document.getElementById('tb3').value = 'after alert'; } </script> </head> <body> <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p> <input type="text" id="tb1" value="" /> <input type="text" id="tb2" value="" /> <input type="text" id="tb3" value="" /> </body> </html> 

我已经search了文档,并没有发现为什么这不起作用的任何线索,这个问题的大多数答案不解决版本2.9.0

提前致谢。

我知道这个问题是关于Phonegap 2.9的,但是当有人找“phonegap alert not working”的时候,这是Google吐出的第一件事。 所以这就是我为了使用Phonegap 3.0所做的工作:

根据手册 ,您需要将插件添加到您的项目。 只需导航到您的项目根文件夹,并写下这个命令:

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

之后,我把这个添加到我的html:

 <script type="text/javascript" charset="utf-8" src="phonegap.js"></script> <script> document.addEventListener("deviceready", onDeviceReady, true); function onDeviceReady() { navigator.notification.alert("PhoneGap is working", function(){}, "", ""); } </script> 

我使用Phonegap 2.9.0,我遇到的问题是我没有将脚本cordova.js添加到页面。

另外请注意,存在一个特定于每个平台的cordova.js文件,所以请注意从iOS上的android添加cordova.js。

请记住,所有对phonegap API的调用都应在deviceready启动后完成

尝试将此function添加到您的config.xml文件..

  <feature name="Notification"> <param name="wp-package" value="Notification"/> </feature> 

..我希望这是帮助…

所有你需要的是添加插件:

 cordova-plugin-dialogs 

然后使用将中断程序stream的警报function:

 alert("some problem here"); 

适用于iOS和Android。