首页 文章

PushPlugin不会在onNotificationGCM上注册设备并返回regid

提问于
浏览
1

Print from console. Execute: ECB and Stopped at registering app

我已经安装了PhonePap 3.4的PushPlugin .

onNotificationGCM案例:注册从未执行,我无法将regid存储在我的服务器数据库中并开始发送通知 .

每当我的应用程序打开时,它都会显示

收到

  • deviceready事件

  • 注册android

  • 成功确定

我已经做好了:

  • 更改了senderid

  • 适用于Android的Google Cloud Messaging - ON

  • 创建服务器密钥(但不应该重要,因为我不在发送部分)

我需要:

  • 安装Google Play服务api?

  • 我缺少什么?

我等了几分钟,但没有注册的消息

$("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");

2 回答

  • 0

    我也有问题 . 删除包含html的代码行 . 如果要检索它,请将其存储到sessionStorage / localStorage,控制台或提醒它 .

    我的html删除版本

    var pushNotification;
    
    document.addEventListener("deviceready", onDeviceReady, false);
    // device APIs are available
     //
    
    function onDeviceReady() {
        pushNotification = window.plugins.pushNotification;
        if (device.platform == 'android' || device.platform == 'Android') {
            console.log("registering android");
            window.plugins.pushNotification.register(successHandler, errorHandler, {
                "senderID": "xxxxxxxxxxx",
                "ecb": "onNotificationGCM"
            }); // required!
        } else {
            console.log("registering iOS");
            pushNotification.register(tokenHandler, errorHandler, {
                "badge": "true",
                "sound": "true",
                "alert": "true",
                "ecb": "onNotificationAPN"
            }); // required!
        }
    }
    
    // handle APNS notifications for iOS
    
    function onNotificationAPN(e) {
        if (e.alert) {
            navigator.notification.alert(e.alert);
        }
        if (e.sound) {
            var snd = new Media(e.sound);
            snd.play();
        }
        if (e.badge) {
            pushNotification.setApplicationIconBadgeNumber(successHandler, e.badge);
        }
    }
    // handle GCM notifications for Android
    
    function onNotificationGCM(e) {
        navigator.notification.alert(e.event);
        switch (e.event) {
        case 'registered':
            if (e.regid.length > 0) {
                navigator.notification.alert(e.regid);
                // Your GCM push server needs to know the regID before it can push to this device
                // here is where you might want to send it the regID for later use.
                console.log("regID = " + e.regid);
                sessionStorage.setItem("deviceId",e.regid);
            }
            break;
        case 'message':
            // if this flag is set, this notification happened while we were in the foreground.
            // you might want to play a sound to get the user's attention, throw up a dialog, etc.
            if (e.foreground) {
                navigator.notification.alert('--INLINE NOTIFICATION--');
                // if the notification contains a soundname, play it.
                var my_media = new Media("/android_asset/www/" + e.soundname);
                my_media.play();
            } else { // otherwise we were launched because the user touched a notification in the notification tray.
                if (e.coldstart) navigator.notification.alert('--COLDSTART NOTIFICATION--');
                else navigator.notification.alert('--BACKGROUND NOTIFICATION--');
            }
            navigator.notification.alert(e.payload.message);
            navigator.notification.alert('MESSAGE -> MSGCNT: ' + e.payload.msgcnt);
            break;
        case 'error':
            navigator.notification.alert('ERROR -> MSG:' + e.msg);
            break;
        default:
            navigator.notification.alert('EVENT -> Unknown, an event was received and we do not know what it is');
            break;
        }
    }
    
    function tokenHandler(result) {
        navigator.notification.alert(result, null, 'Alert', 'OK');
        sessionStorage.setItem("deviceId", result);
        sessionStorage.setItem("notificationServer", "APNS");
        // Your iOS push server needs to know the token before it can push to this device
        // here is where you might want to send it the token for later use.
    }
    
    function successHandler(result) {
        navigator.notification.alert(result, null, 'Alert', 'OK');
        sessionStorage.setItem("deviceId", result);
        sessionStorage.setItem("notificationServer", "GCM");
    }
    
    function errorHandler(error) {
        navigator.notification.alert(error, null, 'Alert', 'OK');
    }
    
  • 1

    解决了 . 经过这么多天的搜索,pushplugin或phonegap都没有错 . 这一轮,它就是手机本身 . 许多人在Android 4.2.2尤其是s4上面临推送通知问题 . 它也不适用于我的Android 4.2.2平板电脑 . 我不知道whatsapp和facebook是如何做到的,只要它们是真正的本机应用程序,所以我相信他们有更多的调试控制权 .

    我是如何解决的......首先我重置了工厂并安装了相同的应用程序..它的工作原理没有任何代码更改!继续前进,因为我担心4.2.2的问题会回来,我已经升级到固件4.3并且现在工作正常 .

相关问题