Push plugin - breaks browser mode


We are integrating push notifications via the Ionic.io Push service. I understand that the push plugin works on a device only, but the error it throws in browser mode is putting me in a catch 22. I can’t use or test the app in browser mode now, the call to push.register() throws out a couple errors:

  • Ionic Push: Disabled! Native push notifications will not work in a browser. Run your app on an actual device to use push.

  • Another registration is already in progress

  • Push plugin not found! See logs

How to work around this behavior? I’d like browser mode to still be available and part of my development flow for obvious reasons.


Did you wrap your push.register() code within a platform ready like this?

this.platform.ready().then(() => {
  console.debug('running on device');
  this.startListeningForPush() over here <----
startListeningForPush() {
    push.register... etc


Hmmm…well I have that, but in the longer chain similar to:

   this.platform.ready().then(() => {
      return this.push.register();
    }).then((t: PushToken) => {
      return this.push.saveToken(t);
    }).catch( (error) => {
	// error handling

The error part always triggers for me right now


OK maybe this resolves it. It looks like I have to gate any calls to Push functions behind:

private canReceivePushNotifications(): boolean {
    return this.platform.is("android") || this.platform.is("ios");

// elsewhere:
if(canReceivePushNotifications()) {
  this.push.register().then( // etc. . . 

Is this what others are doing?


Yes that’s a workaround for your problem I guess. But not one that should be needed though :wink:


Why can’t you just swallow the error and soldier on? It doesn’t appear to be fatal.


I just prefer to always handle any errors. I never leave an empty catch block in Java either.


That’s nice, but the error here is saying “we are not on a platform that can receive these notifications”. I don’t see any substantive difference between trying and failing versus attempting to protect oneself from failing in the first place.


Since I know the call will throw an error in browser mode why would I still do it? As to why not silence the catch block: I still need to catch any other errors that might be thrown from this block for other reasons.