好的,我已经在这个问题上工作了一段时间,但无法解决这个问题。简单的 PhoneGap 测试应用程序,试图显示警报。
使用适用于 iOS 的 Cordova 2.9.0。我添加了一些简单的测试代码并在 chrome 中对其进行了测试,以查看它在哪里中断,因为它在模拟器中不起作用
当我在 Chrome 中测试时(当然模拟器中的结果相同,但没有显示错误消息)
- 它按应有的方式执行 onDeviceReady
- 它将 tb2 文本框值设置为“警报前”
- 然后它因错误而中断: Uncaught TypeError: Cannot call method 'alert' of undefined, 在这一行: navigator.notification.alert(...
它应该正确引用cordova.js,这是我的应用程序文件夹的结构:
- 科尔多瓦插件.js
- 科尔多瓦.js
- /规格
- 规范.html
- 配置文件
- /css
- 主页.html
- /img
- 索引.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>
我搜索了文档,但没有找到任何关于为什么这不起作用的线索,这个问题的大多数答案都没有解决版本 2.9.0
提前致谢。