尝试使用 Phonegap 2.3.0 在 Xcode 4.6 中使用 navigator.notification.alert() 时,我遇到了一个奇怪的问题。
我有两个文件,index.html 和 other.html。单击 index.html 中的“测试警报”会按预期触发警报,但是在解除警报然后导航到 other.html 后,单击“测试其他警报”不会触发警报。
但是,如果您在移至 other.html 之前在 index.html 上单击“测试警报”两次或多次,警报将继续按预期运行。只有在触发一次警报并更改页面后,警报才会一起停止运行。
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 中的模拟器错误?
最佳答案
这个问题存在是因为 Phonegap 2.2 还看到: Notification in PhoneGap for iOS 在 Phonegap 2.3 上的 WindowsMobile 上也有同样的问题。
我没有从 2.1 更新...似乎是它能正常工作的最后一个版本。
不要忘记在上面添加 document.addEventlistener("deviceready", onDeviceReady, true);
。
关于iOS notification.alert() 无法使用 Phonegap 2.3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14730693/