Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova Push Plugin: onNotificationGMC is not fired and cannot obtain regID

Hello everyone I'm developing a cordova Hybrid app that requires the Push Notification Service of Android and iOS to work and so I've installed the cordova plugin "PushPlugin".

Here's my code

document.addEventListener("deviceready", deviceready, false);

function deviceready() {
    try {
        pushNotification = window.plugins.pushNotification;
        pushNotification.unregister(successHandler, errorHandler);
        pushNotification.register(
            successHandler,
            errorHandler, {
                "senderID": "7645XXXXXXXX",
                "ecb": "onNotificationGCM"
            });

        function successHandler(data) {
            alert("SUCCESS: " + JSON.stringify(data));
        };

        function errorHandler(e) {
            alert("ERROR" + e);
        }


        function onNotificationGCM(e) {
            alert("Done")
        }

    } catch (e) {
        alert(e);
    }
}

When I run my application I expect to have two alert: the succesHandler one and the onNotificationGCM one but it only fires the succesHandler one saying: "OK"... With this problem I can't even access the regID parameter that will be stored in my server...

Can someone please explain me how to get the regID.. All my work depend on this

I'm testing this app on a Galaxy S4 Mini with Android 4.4.2.

like image 754
Matteo Cardellini Avatar asked Oct 21 '22 02:10

Matteo Cardellini


1 Answers

FIXED

I moved the onNotificationGCM in an empty script tag like this:

<script>
function onNotificationGCM(result) {
    alert(result.regid);
}
</script>

And now it give you the regID :)

like image 160
Matteo Cardellini Avatar answered Oct 22 '22 15:10

Matteo Cardellini