Phonegap通知在Phonegap开发者android应用程序中不起作用

Phonegap Notification not working in phonegap developer android app

本文关键字:Phonegap 不起作用 应用程序 开发者 通知 android      更新时间:2023-09-26

我正在使用PhoneGap开发人员应用程序在开发过程中测试我的应用程序。但我无法让插件开始工作。在这种情况下,我使用的是通知。JavaScript警报有效,但notification.alert不起作用。拜托,我已经绕了好几天了。以下是我的代码。

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/responsive.js"></script>
<script type="text/javascript">
    app.initialize();
    if(window.localStorage.getItem('session') == null){
        navigator.notification.alert("Not logged in", null, "Login?", "Continue");
        navigator.notification.beep(1);
        navigator.notification.vibrate(1000);
        //alert('not logged in');
        }else{
            navigator.notification.alert("Logged in", null, "Login?", "Continue");
            navigator.notification.beep(1);
            navigator.notification.vibrate(1000);
            //alert('logged in');
            }
</script>

@ITECH-PLANET,
如果您使用PhoneGap开发人员应用程序附带的标准示例,则必须等待deviceready*启动*。

您可以通过将代码的函数部分放入函数中,然后调用该函数来测试这一点。

像这样:

app.notify : function () {
    if(window.localStorage.getItem('session') == null){
        navigator.notification.alert("Not logged in", null, "Login?", "Continue");
        navigator.notification.beep(1);
        navigator.notification.vibrate(1000);
        //alert('not logged in');
    }else{
        navigator.notification.alert("Logged in", null, "Login?", "Continue");
        navigator.notification.beep(1);
        navigator.notification.vibrate(1000);
        //alert('logged in');
        }
}

然后改为:

<script type="text/javascript">
    app.initialize();
    app.notify();
</script>

欲了解更多详细信息,请阅读Cordova/Phonegap 新开发人员的主要错误4