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
fromPushNotification.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
fromPushNotification.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
fromPushNotification.configure
is triggeredPushNotificationIOS.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