-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔥 iOS Background Notifications Not Being Displayed #3805
Comments
background listener needs to be set as early in init as possible, like in index.js or App.js, it must be before you use AppRegistry to add the app view etc - if I understand your provided information correctly, it may not be in the correct place in app init https://rnfirebase.io/messaging/usage#background--quit-state-messages |
I'm getting the same exact issue. Foreground notifications work, but background notifications don't do anything (I receive the notification, but clicking on it launches the app without doing anything). I'm working on a real device and have put my handler as early as possible, in index.js like this:
When I click on the notification, I get this from XCode:
|
In my experience with messaging, no one has the exact same issue. My eyes glaze over now when I see that. I literally stop reading. Make no assumptions about your issue if you want to fix it, because every issue seems to be some unique failure mode. Perhaps this is a difference between direct channel and APNs, see my comment here #3530 (comment) |
any update? |
Update: @mikehardy You are correct, I had initialised my background listeners after the AppRegistry of views etc. I have moved this to the earliest point possible in the initialisation of my application and it seems to not have changed much. I also added the code suggested by @samparmenter here The code I am using to send the message to device is using the Firebase Admin Node.JS SDK and is as follows: let fcmToken = userData['fcmToken'];
console.log(`Sending message to users device...`);
// See - https://firebase.google.com/docs/reference/admin/node/admin.messaging.Messaging#send
let messagingConditionResponse = await messaging.sendToDevice(
// Device registration token (fcmToken)
fcmToken,
// MessagingPayload
{
data: {
"Test data key": "Test data value"
},
notification: {
title: "New Rewards Available!",
body: "Check out the Shop in-app to see our new rewards!"
}
},
// MessagingOptions
{
contentAvailable: true,
dryRun: false,
mutableContent: false,
priority: "high"
}
);
console.log(`Finished sending message...`);
console.log(messagingConditionResponse); This message is being received in the foreground no problem however nothing is being displayed whilst in the background. When I bring the app to the foreground the I have been running on device ( |
Just to clear something, you mean that that the notification doesn't show on the notification area on iOS? |
The notification is not displayed i.e on the top of the mobile screen when any notification is received. This happens in both the background and quit state. |
Do you have an apple developers license? |
I'm having a similar issue. I can receive foreground notifications via However, the notification banner isn't being shown nor does it show up in the notification tray on IOS. If both my foreground/background handlers are called as expected, I must've setup IOS cloud messaging correctly to some extent. Really loving this module so far though! |
@Wmeng98 I believe that is functioning as the upstream SDKs define it should function. For local notification handling on foreground you need a local notification package. Those are related but both enormous sets of functionality largely separate from react-native-firebase so this module doesn't cover them. |
Thanks for the quick reply @mikehardy! I've also tested push notifications via curl to apns push server
Funny thing is I can see the badge update but no notification banner while in background state of the app. Thanks! P.S My device is running iOS 13.5.1. |
Maybe it is just a matter of setting the right APNS headers, a priority or critical or similar? I'm not good enough to know it off the top of my head but there are mentions of APNS headers related to notification displaying or not all over - should pop up in a search and might work with experimentation |
Yea, adding the right APNS headers helped me get the After some more googling, It turns out I hadn't requested the right permissions using If you want to check authorization natively on IOS (objective-c), include the following in your
Though this should be done via the Thanks again for the quick feedback @mikehardy 👍 |
I actually encourage everyone to use react-native-permissions - https://github.com/react-native-community/react-native-permissions/ - it is by far the best way to manage permissions IMHO - glad you got your messages through, I want to pass the credit for idea of the headers right along to @forbesgillikin I got the idea from there (but didn't have the link handy) and now there's even a PR #3882 - this stuff is just plain difficult, but we're getting through it together. Cheers |
I tried the options suggested by Wmeng98 but still no luck. I am able to get notifications in foreground but it is not working in background. One more observation : I kept the app in background, send a notification , now when I open the app onMessage() handler is getting called which is not expected as my app was in background. I tried this with two different version of react-native-firebase/messaging. 6.4.0-rc4 and 7.3.2. With both versions I am getting same behaviour. It would be really helpful if someone let me know what I am missing here to add background notification for iOS ? |
You added the proper apns headers to your message as suggested above @Shweta-Porwal? |
I am sending it from FCM console. I believe from FCM console we don't have
to write any header, right ? Also do we need to add react-native-push-notification framework for this to work?
…On Tue, Jul 7, 2020 at 8:11 AM Wilson Meng ***@***.***> wrote:
You added the proper apns headers to your message as suggested above
@Shweta-Porwal <https://github.com/Shweta-Porwal>?
How are you sending push notifications? FCM console? Admin SDK?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3805 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AM3FEDNJ5LXNV77QM77GOZTR2KDMTANCNFSM4OCYWU2Q>
.
|
The only way to properly test cloud messaging is to craft the JSON yourself and send it via firebase-admin, it's not that with the console "we don't have to write any header", it's that with the console you don't even get the chance, so you don't stand a chance of getting things exactly right |
{ |
@Shweta-Porwal read the comments above carefully, confirm you have the permission granted per above and follow the link to the PR for the documentation and add the appropriate headers - there is already info in this thread that seems important and is not included in the JSON you posted, which makes me think this will be an inefficient use of my time helping troubleshoot - don't do that or I will not pay attention going forward |
Your request is malformed and does not include the APNs headers that are necessary to push data-only messages in the background on iOS. Your request should look like {
"to" : //device fcm token,
"notification" : {
"data" : {
"body" : "Test Message",
"title" : "React Native Firebase",
},
"aps" : {
"content_available" : 1
}
} With
As headers in the request. Using Postman will require a different json block than what is described in the RNFirebase docs. Either use the Node Admin SDK and use the RNFirebase documentation or become familiar with the FCM and APNs documentation |
I am gettting crazy to make it work on background or quit mode on IOS. The notifications do work on foreground. Android notifications work perfect. This is my code: AppDelegate.m
index.js
App.js
Postman request (Added all the content_available possibilities as I was. not sure which one. should I use)
|
I posted my problem in new ticket: |
Hello 👋, to help manage issues we automatically close stale issues.
|
@mikehardy having same issue. Errors are thrown when app is backgrounded. When I send first message, it is not shown and this error is thrown. When next message is sent, previous notification is handled by background handler, so it is one message lag. When I open app latest message is handled. Strangest part here is, that when I enable Background location tracking - Expo Location package, and repeat the same, no error is thrown and each message is handled. Have googled everywhere but no luck to identify what is the problem. Maybe you can suggest me something, were can I look or troubleshoot this. |
This error looks related to Xcode not Firebase. Also, iOS simulators will not handle notifications. They must be tested on a real device. |
@forbesgillikin checked link u provided. As I see I have only one version Xcode, also done mac restart, so no success on this. Were running app on device, not simulator. |
Maybe use this pull request for inspiration and add to the constant wait even more? 415dba4 |
@mikehardy @compojoom so make some investigation, and understood that issue is with this line: dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ when I take it out, and leave without dispatch_after it works. Also what I found out, that dispatch_after is not triggered on first message, after it is backgrounded. |
I would like to keep information related to that line centralized on the issue I just cross-posted to. It is a specific issue. |
Hello 👋, to help manage issues we automatically close stale issues.
|
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. |
I got this working on iOS 13 and 14 by changing the p8 APN auth certificate on firebase console cloud messaging to p12 certificate generated from the Push Notifications feature under the app's provisioning profile in the apple developer account |
iOS Background Notifications Not Being Displayed in React Native App Environment |
For me when sending data-only notifications and the app is in the background it doesn't work on a simulator but works on Real Devices. |
Hi @furqan-fabtechsol , Hi @mohamedshawky982 , Thank you! |
My payload is as given below
Apdelegate.mm file is as given below
Index.js File
I still not found solution |
Hi @furqan-fabtechsol , Thank you for the response! Even I am in the same state. Without a solution. Need to check with @mohamedshawky982 once. |
+1 |
Guys, I found a solution. sendMulticast is deprecated and you should use sendEachForMulticast instead. |
Hi @miladnikad , I have been using the sendEachForMulticast itself. Can you share your message body? Thanks! |
Issue
I am currently performing a version upgrade from
"react-native-firebase": "^5.5.5"
to the latest libraries following the migration documentation (https://rnfirebase.io/migrating-to-v6). I have successfully migrated and tested all other Firebase libraries that my application uses however, I am having an issue with background notifications not being displayed on iOS devices using themessaging()
library. Foreground notifications work as expected on both Android & iOS and background notifications also work on Android as expected.Firstly, when my app is initialised, the following code is ran:
And following this the Firebase messaging listeners are created. In particular the background listener below is not being triggered:
However, the foreground listener such as below fires as expected when the app is running in the foregroud:
Happy to provide any more necessary/useful debugging information upon request.
Note: I have read through the following issues and applied many of the suggested possible solutions and have yet to come across one that works for me to fix this issue.
Project Files
Javascript
Click To Expand
package.json
:firebase.json
for react-native-firebase v6:iOS
Click To Expand
ios/Podfile
:AppDelegate.m
:Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:// N/A
android/app/build.gradle
:// N/A
android/settings.gradle
:// N/A
MainApplication.java
:// N/A
AndroidManifest.xml
:<!-- N/A -->
Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:See package.json for submodule version numbers
Firebase
module(s) you're using that has the issue:Messaging
TypeScript
?No
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: