【问题标题】:navigator.notification.alert not working - phonegapnavigator.notification.alert 不工作 - phonegap
【发布时间】:2013-12-17 06:17:56
【问题描述】:

我正在为 iphone 做一个 phonegap 项目,我在确认通知回调中有一个 phonegap 警报。我的confirmation (navigator.notification.confirm) 工作正常,但alert(navigator.notification.alert) 不工作,不知道为什么会这样,将我的代码粘贴在下面。

function confirmSubmit() {
    navigator.notification.confirm(
        'Are you ready to submit?', // message
        function(buttonIndex) {
            onConfirm(buttonIndex);
        },
        'Confirmation', 'Yes,No' // buttonLabels
    );
}

function onConfirm(buttonIndex) {
    if (buttonIndex === 1) {
        didClickSubmitButton();
    } else if (buttonIndex === 2) {
        return false;
    }
}

function didClickSubmitButton() {
    validate();

    ----some other codes-----
}

function validate() {
    navigator.notification.alert("my alert"); // Not working
    alert("another alert") //Working
}  

 

我正在测试 xcode 的 iphone 模拟器,我需要你的帮助。谢谢。

【问题讨论】:

  • 我经历过,它不适用于 iphone 模拟器 3.5,但它适用于 iPad 模拟器。假设您在 deviceready 事件之后调用了navigator.notification.alert
  • 设备就绪在开始。
  • @JunM:它可以在设备中使用吗?
  • 我只能在 android 设备上确认它可以工作,但尚未在 iOS 设备上测试。对不起。
  • 如果将navigator.notification.alert("my alert") 放在confirmSubmit 方法的第一行,行吗?

标签: cordova alert


【解决方案1】:

我在 android 中遇到了同样的问题。

navigator.notification.alert() 不工作,但 alert() 工作。自定义我希望 navigator.notification.alert() 工作的警报。

所以我添加了通知/提示等插件:

$cordova plugin add org.apache.cordova.dialogs

然后将以下代码添加到 app/config.xml:

<feature name="Notification">
        <param name="android-package" value="org.apache.cordova.dialogs.Notification" />
</feature>

因此我得到了 navigator.notification.alert() 处理标题、消息、回调和按钮名称参数。

【讨论】:

  • 根据docs.phonegap.com/en/3.0.0/…应该是app/res/xml/config.xml,而不是app/config.xml
  • org.apache.cordova.dialogs 已重命名为 cordova-plugin-dialogs
【解决方案2】:
function validate ()
{
  navigator.notification.alert('Mesage',
                               null,
                               'Title',  
                               'OK')
 }

【讨论】:

    【解决方案3】:

    你的按钮标签应该用括号括起来,就像符号一样。有关代码示例,请参阅文档。 http://cordova.apache.org/docs/en/3.1.0/cordova_notification_notification.md.html#notification.confirm

    【讨论】:

    • 在比较数字时尝试使用 == 而不是 ===。
    • 没关系,因为它正好在警报上方。
    • 或者使用开关代替。验证函数是否实际被调用?
    【解决方案4】:

    如果您是从 IDE 运行它,请确保您已在 IDE 本身中为您的项目添加/选择了 cordova 插件。

    例如:

    如果是 Netbeans,右键单击项目,选择属性,从树中选择 cordova 并单击插件选项卡,检查所选 API 中是否有对话框通知。

    如果不是这个原因,每次你都会从命令行添加它,并且如果尝试从 IDE 运行它,它会擦除​​/清理插件目录,但只有在你让 cordova 运行 android 时才能从命令提示符处正常运行。

    我希望以上内容会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多