Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16552

How to differentiate whether a notification is being received or opened?

$
0
0

I'm quite lost here with how could we differentiate when a notification is RECEIVED? or OPENED?. So we can perform a callback action depending on its state.

In the documentation of react-native-push-notification, onNotification is triggered when a remote notification is received / opened or when localNotification is opened. This is not helpful to perform any action, since we don't know if the user has tapped on it.

With this setup, here's the behaviour:

Android

When App at Foreground received & tapped banner

  • onNotification from PushNotification.configure is triggered
  • For whatever reason, PushNotificationIOS.addEventListener('notification', ()=>{'remote notification is called!')}); get triggers as well.

When App at Background received banner

  • nothing is processed, need to set a handler via the "setBackgroundMessageHandler" method.

When App at Background tapped banner (pull down status to press)

  • onNotification from PushNotification.configure is triggered
  • For whatever reason, PushNotificationIOS.addEventListener('notification', ()=>{'remote notification is called!')}); get triggers as well.

iOS has 2 different behaviour, depending which one you setup with

iOS Case 1:With the suggestion given by @mtettmar here

When App at Foreground & Background received banner

  • nothing happened

When App at Foreground & Background tapped banner

  • onNotification from PushNotification.configure is triggered
  • PushNotificationIOS.addEventListener('localNotification', ()=>{console.log('localNotification is called')});

iOS Case 2:if you go with the following setup (you're going with this setup, most likely you are requesting device permission at a later stage, instead at the app launch state)

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];  center.delegate = self;

When App at Foreground & Background received banner

  • nothing happened

When App at Foreground & Background tapped banner

  • nothing happened

Viewing all articles
Browse latest Browse all 16552

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>