phonegap-build / PushPlugin

This repository is deprecated head to phonegap/phonegap-push-plugin
https://github.com/phonegap/phonegap-plugin-push
MIT License
1.32k stars 1k forks source link

Recursive register on registered fails #688

Closed oriolg23 closed 7 years ago

oriolg23 commented 7 years ago

Hello,

I write this lines to ask if someone has got a simliar problem like me and how can i try to solve it...

I use this plugin for register users in GCM for Android, and I call the register function every time that the user opens the apk for prevent some errors. But it isn't still enough, because after to get the token, I call Amazon Web Services to obtain or register (if i haven't got it) a new endpoint in my Amazon application.

I need that this workflow works always because this endpoint is used to send push notifications using a database and I observed that sometimes the register function fails giving me a null endpoint... After tested the call to Amazon Web Services I've seen that it's correct so i think to call the register function every time that i have an errorCallback making the code recursive.

This will be a good idea or any idea to make the code works 100% to success register every time?

Thanks in advance,

Oriol

The code (resumed):

pushNotification.register(successHandler, errorHandler, {"senderID":"783684761403","ecb":"onNotificationGCM"});

$window.onNotificationGCM = function(e) {
                    switch( e.event )
                    {
                           case 'registered':
                                token = e.regid;
                                $window.localStorage.setItem('token', JSON.stringify(e.regid));
                                amazon();
                           break;
                    }
}

function errorHandler (error) {
                console.log(error);
                reregister();
           }

           function reregister(){
                console.log("Tornem a registrar, hi ha hagut error en el registre");
                pushNotification.register(successHandler, errorHandler, {"senderID":"783684761403","ecb":"onNotificationGCM"});     // required!
           }
oriolg23 commented 7 years ago

I close this bug, I'll use the new push plugin (phonegap-plugin-push) waiting that this issue is not reproducet on it.