remove push notification listener

#1

I’d like to remove the remote push notification listener at some point but it seems not to work.

  componentDidMount() {
    registerForPushNotificationsAsync();

    // Handle notifications that are received or selected while the app
    // is open. If the app was closed and then opened by tapping the
    // notification (rather than just tapping the app icon to open it),
    // this function will fire on the next tick after the app starts
    // with the notification data.
    this._notificationSubscription.handler = Notifications.addListener(this._handleNotification);
   console.log(this._notificationSubscription)
  }

 componentWillUnmount() {
      this._notificationSubscription.handler.remove();
      console.log(this._notificationSubscription)
}

Although console.logs seem fine and the listener seems to be removed, I’m still keeping receiving notifications on my device:

10:06:01 AM
Object {
  "handler": EmitterSubscription {
    "context": undefined,
    "eventType": "notification",
    "key": 0,
    "listener": [Function anonymous],
    "subscriber": EventSubscriptionVendor {
      "_currentSubscription": null,
      "_subscriptionsForType": Object {
        "notification": Array [
          [Circular],
        ],
      },
    },
  },
}
10:06:02 AM
Object {
  "handler": EmitterSubscription {
    "context": undefined,
    "eventType": "notification",
    "key": 0,
    "listener": [Function anonymous],
    "subscriber": null,
  },
}

Is there anything I am doing wrong? Or is it because I am using the Expo client (not standalone app)?

#2

Not sure for Expo client but in Standalone apps you have to remove the Notification token from your notification publish list.

1 Like
#3

Maybe this is because it is running in dev mode?? Try exp start --no-dev --minify to emulate a prod build

#4

That did not help. However it seems to work on the standalone app version.

So good news is that is working as supposed, though only on the standalone version. I’m willing to update the docs if you can point me out where exactly.

#5

Sorry, for the false positive. It actually does not work on standalone app either.

#6

Hmm, we are actively working on Push Notification edge-cases. I’m still not quite sure why this doesn’t work for you though. :thinking:

closed #7

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.