【问题标题】:iOS notification.alert() not working using Phonegap 2.3.0iOS notification.alert() 无法使用 Phonegap 2.3.0
【发布时间】:2013-02-06 13:49:58
【问题描述】:

尝试在 Xcode 4.6 中使用 Phonegap 2.3.0 使用 navigator.notification.alert() 时遇到一个奇怪的问题。

我有两个文件,index.html 和 other.html。单击 index.html 中的“测试警报”会按预期触发警报,但是在解除警报然后导航到 other.html 后,单击“测试其他警报”不会触发警报。

但是,如果您在 index.html 上单击“测试警报”两次或更多次,然后再转到 other.html,则警报将继续按预期运行。只有在触发警报 ONCE 并更改页面后,警报才会一起停止运行。

index.html

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="cordova-2.3.0.js"></script>
        <script type="text/javascript" charset="utf-8">
            function alertTest() {
                navigator.notification.alert('Testing', null, 'Alert Test', 'OK');
            }
        </script>
    </head>
    <body>
        <a href='other.html'>Move to other page</a>
        <a href="#" onclick="alertTest(); return false;">Test the alert</a>
    </body>
</html>

其他.html

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="cordova-2.3.0.js"></script>
        <script type="text/javascript" charset="utf-8">
            function alertTest() {
                navigator.notification.alert('Testing', null, 'Alert Test', 'OK');
            }
        </script>
    </head>
    <body>
        <a href="index.html">Go back</a>
        <a href="#" onclick="alertTest(); return false;">Test the alert</a>
    </body>
</html>

我完全不知道为什么会发生这种情况,因为在我的应用程序中,我需要能够在不同页面上的按钮按下时触发警报,这在本示例中似乎是偶然发生的。

非常感谢任何朝着正确方向的帮助或推动!

更新:

这似乎只发生在 iOS 6 和 6.1 模拟器上。当警报没有弹出时,按主页键然后再次打开应用程序会使丢失的警报立即出现。

这个例子也有同样的行为:http://docs.phonegap.com/en/2.3.0/cordova_notification_notification.md.html#Notification

谁能确认这是否只是最新 ​​Xcode 中的一个模拟器错误?

【问题讨论】:

  • 您可以添加 作为您的文档类型吗?
  • 感谢您的建议,这在我的代码中只是没有在上面发布。编辑了我上面的原始帖子以反映这一点。
  • 你的代码对我有用...
  • 您是在 iOS 5 还是 6 上进行测试?玩过之后,这似乎只是 iOS 6/6.1 的问题(至少在模拟器上,无法在实际设备上测试)。您是否尝试过使用模拟器或设备重新创建?

标签: ios cordova alert


【解决方案1】:

此问题自 Phonegap 2.2 开始存在,另请参阅: Notification in PhoneGap for iOS WindowsMo​​bile 在 Phonegap 2.3 上的同样问题。

我没有从 2.1 更新...似乎是它正常工作的最后一个版本。

别忘了在上面加上document.addEventlistener("deviceready", onDeviceReady, true);

【讨论】:

    【解决方案2】:

    更新到最新版本的 phonegap (2.4.0)。似乎可以解决问题。至少对我来说,现在一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      • 1970-01-01
      • 2023-03-23
      • 2013-08-14
      相关资源
      最近更新 更多