无法读取未定义的属性PushNotification

时间:2015-10-24 09:47:36

标签: cordova push-notification

我收到错误

  

无法读取属性PushNotification of undefined

我已经包含了所有必需的脚本文件。请帮忙。

$(document).on('pageinit', '#login', function(){
    $( document ).ready(function() {
        var pushNotification ;

        try {
            pushNotification = window.plugins.PushNotification;
            alert("android");
            pushNotification.register(successHandler , errorHandler, { "senderID": "619025542236", "ecb": "onNotificationGCM" });    // required!
        }  
        catch (err) {
            txt = "There was an error on this page.\n\n";
            txt += "Error description: " + err.message + "\n\n";

            //console.log(txt);
            alert(txt);
        }
        function successHandler(result) {
            alert('Callback Success! Result = '+result)
        }
        function errorHandler(error) {
            alert(error);
        }


        function onNotificationGCM(e) {
            switch( e.event )
            {
                case 'registered':
                    if ( e.regid.length > 0 )
                    {
                        console.log("Regid " + e.regid);
                        $.post("http://dashboard.kanalytics.in/kore/webservices/dashboard_gcm_insert.php",
                        {
                            regid : e.regid,
                            name : "",

                            //name:"rohit",
                            //email:"jiten.ktm@gmail.com"
                        });
                        alert('registration id = '+e.regid);
                    }
                    break;

                case 'message':
                    // this is the actual push notification. its format depends on the data model from the push server
                    alert('message = '+e.message);
                    var message = document.getElementById(e.message);
                    window.plugins.statusBarNotification.notify("Dashboard Notification", e.message);
                    var sound = new Media("assets/www/"+e.sounds);
                    sound.play();   
                    break;

                case 'error':
                    alert('GCM error = '+e.msg);
                    break;

                default:
                    alert('An unknown GCM event has occurred');
                    break;
            }
        }

1 个答案:

答案 0 :(得分:0)

看起来你还没有将PushNotification插件添加到Cordova项目中,这就是pushNotification对象未定义的原因。