Comments (10)
Hi @Shervanator ,
Thank you for taking the time to reply, much appreciated.
It seems similar to the issue you quoted #7770 but still slightly different in this case, because
- background messages are working
- the push notifications are not data only.
It is interesting what you described above with what is happening after Force close and sending again. Unfortunately, that is not working for me. I briefly tried that with both of our apps and didn't seem to work. The only difference in what I did is me sending from AWS SNS - later I will try using the Firebase console too.
I was playing around with setting "messaging_ios_auto_register_for_remote_messages": false
and registering manually in the code with await messaging().registerDeviceForRemoteMessages();
but that didn't make any difference.
I will let you know if there is any progress.
Thank you,
Tibor
from react-native-firebase.
Okay I've narrowed my problem down, not sure if its similar to what you are seeing:
- Fresh install app
- Register for provisional push notifications
- Send message containing data to app
- onMessage does not fire
- Force close app
- Send message containing data to app
- onMessage now does fire
So maybe I'm running into a different issue, but that is my reproduction steps...
from react-native-firebase.
Hello,
You must add the following code to the appropriate iOS files if the foreground isn't functioning in iOS.
AppDelegate.m
//Called when a notification is delivered to a foreground app. -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { if (@available(iOS 14.0, *)) { completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionBanner | UNNotificationPresentationOptionList | UNNotificationPresentationOptionBadge); } else { completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge); } }
index.js
const unsubscribeNotification = messaging().onMessage(async (remoteMessage) => { if (Platform.OS === "ios") { PushNotificationIOS.addNotificationRequest({ id: remoteMessage?.messageId + "", title: remoteMessage?.data?.message || "", body: remoteMessage?.notification?.title || "", userInfo: remoteMessage?.data, isCritical: true, isSilent: false, sound: 'default' }); } else { this.displayNotification(remoteMessage); } });
from react-native-firebase.
Seems like the same issue as: #7770
I am also noticing this... onMessage is not firing very often (was working reliably in the past), I am occasionally getting it to fire on iOS, but can't identify anything in particular thats making it work?
I did upgrade to react-native-firebase v19.2.2 yesterday (was previously on v16) but rolling back to the old version doesn't seem to help...
I wonder if this is something to do with Firebase/Apple? 🤔
(btw everything is working fine on Android)
from react-native-firebase.
Okay I have noticed one slightly strange thing...
- Install fresh version of my app
- Register for provisional push notifications
- Get FCM token and send a message via Firebase messaging UI => I get nothing when the app is open
- Force close App
- Send a message via Firebase messaging UI => I see the provisional message
- Tap the message => Opens the app
- Send a message via Firebase messaging UI => onMessage fires successfully
So it seems like after clicking the firebase message once will result in onMessage starting to fire correct again on iOS? 🤔
from react-native-firebase.
Very interesting - that's good testing...
- would be interesting to know the exact FCM contents you can post the FCM REST API (with a different device token, of course) to trigger this behavior so anyone trying things can know with certainty they are reproducing exactly the same
- it appears something about the app device API usage around notification registration or token creation or something similar has an issue. Maybe a race condition maybe something else? It looks like there is a missing step 1a of "open app first time", and 5b "open app again" since we are talking about foreground onMessage receipt yes?
- something that is happening either in step 2 permission post / accept and 5b "open app again" (app initializes...) needs to also happen either in 1a "open app first time" or after 2 (permission post / accept) it seems?
from react-native-firebase.
Thanks for the reply @mikehardy!
- The payload I'm currently sending for this test is via the firebase messaging console UI, its a simple message with a title, body, and a data payload. I realise this isn't really data-only, but at least on Android (and I believe on iOS in the past) the app would still have onMessage called so it could handle the push notification without showing the alert in the notification centre. Tomorrow I can try sending a payload via the FCM server side api and send through the exact payload...
- Yep this is in regards to foreground onMessage
- I'll have a little peak into this to see if I find any more interesting info...
from react-native-firebase.
Thank you @Shervanator & @mikehardy for taking the time to check, it is really appreciated.
In my case the onMessage is working correctly when sending the notification from the Firebase Console.
Unfortunately, switching to sending through Firebase is not an option. Our backend have AWS SNS built in and no intention to re-structure it.
Is there a way through APNS payload to force the onMessage to react? This is what we are sending:
{
"aps": {
"alert": {
"title": "Tibor testing",
"body": "Test001"
}
},
"url": "https://www.azonetwork.com"
}
I tried to add "sound": "default"
and "badge":1
- still the same.
Any help would be appreciated.
from react-native-firebase.
Unsure but I think you may need the high priority keys? A differential comparison of what your system sends vs what works when you send via the FCM REST API (so you have complete control of the JSON, critical here during testing) is how I'd go about it
from react-native-firebase.
Thank you so much guys, it is now working 🎉
The onMessage
function worked correctly when notifications were sent from the Firebase console, but our backend uses AWS SNS, and switching to using Firebase REST API would be too complicated.
Investigating further, I found useful discussions in old GitHub issues (e.g. #3479 and #5908) addressing problems with the gcm.message_id
key.
Rather than altering the code in RNFBMessaging+UNUserNotificationCenter.m
by removing the if (notification.request.content.userInfo[@"gcm.message_id"])
condition (which risks being overwritten during updates), I opted to add a dummy gcm.message_id
to the payload. This solution proved to be effective.
{
"aps": {
"alert": {
"title": "Sample Title",
"body": "Sample Message"
}
},
"url": "https://example.com",
"gcm.message_id": "123"
}
I wish it was mentioned in the documentation, it would save tons of time - maybe this summary will help others going forward.
from react-native-firebase.
Related Issues (20)
- [🐛][iOS] - Remote config - Crash app when launching app HOT 3
- [🐛] (Automated/Scheduled) Push Notifications NOT working in iOS HOT 1
- :fire: Error Using loadBundle() in Firestore: Unknown error or an error from a different error domain. HOT 7
- [🐛] firestore get document data doesn't work on RN0.74.1 and 20.0.0 HOT 1
- [🐛] A problem occurred evaluating project ':react-native-firebase_app'. It is too late to set namespace It has already been read to configure this project. HOT 1
- [📚] Documentation Issue Title - Migrating to v6 HOT 2
- [🐛] Firestore get document doesn't work in production HOT 6
- /ios/Pods/Headers/Private/grpc/gRPC-Core.modulemap' not found HOT 1
- Missing Item fields for GA4 in Analytics HOT 5
- [🐛] Icon notification not display in xiaomi devices - CHANGE ME HOT 1
- [🐛] java.lang.ExceptionInInitializerError on Background Notification in quit state. HOT 1
- [🐛] App Check - Firestore permission denied after updating app through TestFlight HOT 1
- [📚] Update Google Analytics for Firebase (GA4F) iOS SDK to Version 10.24.0 or Later HOT 11
- [🐛] import { firebase } from '..'; | Returns a Messaging instance for the given app. (messaging/analytics) HOT 2
- [🐛] 🔥 firestore.Filter.where is undefined. HOT 1
- Type Change Clarification/Justification HOT 3
- [🐛] Android build failed HOT 10
- auth().onAuthStateChanged not triggering on user sign up. HOT 2
- [🐛] Firebase Performance Monitoring Dashboard Doesn't Display CPU and Memory Usage for User Sessions HOT 2
- [🐛] Androind - onAuthStateChanged does not fire when I refresh the app from the metro teminal by pressing R
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-firebase.