【问题标题】:Notification.alert is not working in phonegap build 3.1.0Notification.alert 在 phonegap build 3.1.0 中不起作用
【发布时间】:2014-01-29 04:48:31
【问题描述】:

我正在创建一个 phonegap 应用程序。我使用了 notification.alert 来显示消息。在更新 phonegap 3.1.0 之前,notification.clert 工作正常。正如我使用 phonegap 2.9.0 完成了大约 5 个应用程序一样。在每个应用程序中我都使用了来自this的notification.alert

现在我已经在 2014 年 1 月 28 日构建了我的工作项目,它显示只有 3 个应用程序(Iphone、android 和 windows)可以使用 phonegap 完成。我正在为 IOS 和 Android 创建。一切正常,除了警报。新的phonegap有什么问题吗?是否有任何新的方法或命令来显示警报消息?

请帮助我为什么它不起作用。如果您有任何其他想法,请帮助我。

【问题讨论】:

    标签: cordova phonegap-build


    【解决方案1】:

    从 3.0 版开始,Phonegap/Cordova 将设备级 API 实现为插件,因此您必须将其包含在 www 文件夹中的 config.xml 中

    <gap:plugin name="org.apache.cordova.dialogs" />
    

    或者像这样从 phonegap CLI 手动添加:

     $ cordova plugin add cordova-plugin-dialogs
     $ cordova plugin ls
        [ 'org.apache.cordova.dialogs' ]
     $ cordova plugin rm org.apache.cordova.dialogs
    

    包含之后就可以这样使用了

    <!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 device API libraries to load
        //
        document.addEventListener("deviceready", onDeviceReady, false);
    
        // device APIs are available
        //
        function onDeviceReady() {
            // Empty
        }
    
        // alert dialog dismissed
            function alertDismissed() {
                // do something
            }
    
        // Show a custom alertDismissed
        //
        function showAlert() {
            navigator.notification.alert(
                'You are the winner!',  // message
                alertDismissed,         // callback
                'Game Over',            // title
                'Done'                  // buttonName
            );
        }
    
        </script>
      </head>
      <body>
        <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>
      </body>
    </html>
    

    您可以进一步研究here。编码愉快!

    【讨论】:

    • 昨天我也从 2.9 升级时偶然发现了一个类似的问题。很高兴我能帮忙:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-06
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    相关资源
    最近更新 更多