onNotificationDisplayed does not trigger even when content_available set to true in push notification payload
Environment Application Target Platform: iOS Development Operating System: macOS Mojave 10.14 xcode : 10 React Native version: "react-native": "^0.55.4" React Native Firebase Version: 4.3.8 Firebase Module: database, auth, messaging, storage ( just removed crashlytics and perf ) Are you using typescript? NO
According to https://rnfirebase.io/docs/v4.3.x/notifications/introduction onNotificationDisplayed should be triggered if set content_available : true in push notification payload my cloud function to send push is as above but it triggers only when app is in foreground not when app is in background .
PushNotificationFromProfanity(topic_id, title, body, data ){
var senddata = { sample: "true" }
if ( typeof data !== 'undefined' && data !== null && typeof data === 'object' ){
senddata = data
}
var payload = {
notification: {
title,
body,
},
data: senddata,
topic: topic_id,
android: {
notification: {
sound: 'default',
color: '#f45342',
icon: 'ic_launcher'
}
},
apns: {
payload: {
aps: {
sound: 'default',
content_available: true,
}
}
}
};
console.log('payload',payload)
return admin.messaging().send(payload)
}
my onNotificationDisplayed is as follows :
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification: Notification) => {
firebase.notifications().getBadge()
.then( count => {
count++
firebase.notifications().setBadge(count)
})
.then(() => {
console.log('Doing great')
})
.catch( error => {
console.log('fail to count')
})
});
Same here, would be great if anyone can help with this. By the way try testing it while your app is running on Xcode cus mine works in that case but the moment it says "Finished running
.. and according to this page https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html its name it should be content-available instead of content_available , but using content-available throw syntax error due to hyphen , that is why I tried to use 'content-available' : '1' too but did not get success.
Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.
Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.
@amitbravo @Osebrian i found it works but strangely onNotificationDisplayed work only on foreground not on background and when the app is closed
@reynaldpn Did you find a solution when the app is on background? I need to listen when notification is RECEIVED on background (not tapped). onNotificationDisplayed only works on foreground.
@mikehardy Could you tell us if there is any event which we can use to detect when a notification is received on background (not tapped or clicked, just received). Notification + data messages. Thanks (Android)
@fgagneten have you found a solution for this yet?
I've been at it for some time now with no luck... I'm thinking of overriding onNotificationReceived and send an event to react-native once a notification is received. For this to work though background & foreground though first I'll need to start manually building my push notifications and also send them as data-only (onNotificationReceived with regular notifications is called only on background),
Having the same issue here, all other listeners seem to be working as expected however onNotificationDisplayed doesn't seem to fire when app is in background. I want to use this method to update the badge on the app also. Running in Release mode on Device (iOS). Can provide further details if necessary.
Edit: I am also passing the following as part of the push notification:
"options": {
"content_available": true
}
Have also tried contentAvailable instead of content_available to no avail.
@dooleyb1 This issue has been closed for a while and people probably won't pay much attention but the problem persists. Perhaps open a new one?
@mstankov Actually managed to (somewhat) resolve my problems there. I had to sign out of my account and then delete and re-build the app in Release mode which would cause my app to prompt me to accept push notifications (could receive them previously but wouldn't fire the onNotificationDisplayed listener for whatever reason). Once I've rebuilt and accepted push notifications again and signed in everything works as expected. However, I have to repeat this whole auth process again when I want to re-test. Will update again if I get any further on this.
@dooleyb1 this might be due to new iOS13 messaging permissions things, have you tried managing the permissions separately with react-native-permissions? Others have had success with that, and it's what I rely on for all permissions interaction
@mikehardy Ah interesting. No as of now we only use firebase.messaging().hasPermission() and firebase.messaging().requestPermission() to check and request for permissions. Will take a look at react-native-permissions and see if this resolves anything.