Unable to get pushObject.on('register') by using pushObject.init() after calling the function pushObject.unregister() and without app reloading


#1

Hello,
Ionic : 3.20.0

I have implemented Push Notifications using Ionic-Native and used Phonegap Plugin Push.
I am able to receive push notifications as well as unregister for push notifications. But the problem arises after I unregister the app from push notifications, I can’t really inititate push notifications again, or the pushObject.on(‘registration’) event handler is not called WITHOUT killing the app and starting it again.
Process: I am actually calling the pushObject.init() function when I log into my app, and then listening to the pushObject.on(‘registration’) event. Then, redirecting to the dashboard page.
Every time I open the app and its logged in, It is redirected to the Dashboard page where it listens to the pushObject.on(‘notification’) function. Everthing works fine till here when I login for the first time.

Then when I am logging out the user, I call the pushObject.unregister() function. This means I wont get any notifications on this device from the specified Sender ID.

Now WITHOUT killing the app, if I try to login again, I am unable to get a new Token ID, as I call the pushObject.init() in the login Part, but it doesn’t call the handler pushObject.on(‘register’), unlike it did the first time.

But, if I kill the application and launch it again after I have logged out and not logged in, then when I log in, again the Handler pushObject.on(‘registration’) is called after I call pushObject.init() function.

I have gone through the web and reached this point. :

“The unregister method is used when the application no longer wants to receive push notifications. Beware that this cleans up all event handlers previously registered, so you will need to reinitialize the plugin’s API (through .init()) if you want them to function again without an application reload.”

But I can clearly see that even if I call pushObject.init() function while logging in after I have logged out, I can’t seem to get hold of the pushObject.on(‘registration’) handler.

Can anyone help?