-
Notifications
You must be signed in to change notification settings - Fork 4k
[firebase_messaging]: iOS background message not invoked when app is terminated and user switches to different app afterward #9625
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
Comments
We just noticed that OneSignal provides the feature. Please see Step 3 of follow documentation: Is it possible to have something like that also in Firebase_Messaging? |
@iosephmagno |
@hatemragab we are investigating. The idea is, if we get to modify remote notification content before diplaying headup on iOS, we can use Redis on the server to map users’ devices so that:
As of now, it seems that this is the only way to deal with notifications when content decryption and 100% delivery is required on iOS. If firebase_messaging adds a Notification Extension, above idea will require minimal code on our side. Otherwise, we must use a different plugin on iOS and use firebase_messaging on android only. |
Thanks for the detailed report. Based on the details provided and also additional context provided, I am keeping this issue open and treating as a potential enhancement and to know team's insights on it. /cc @russellwheatley |
I took a look since @iosephmagno emailed me about this issue. Some challenges to support this include:
|
Hi! |
@awaik unfortunately you must use iosNotificationExtension. At least, by doing so you will have ios Communication Notification layout on your app. I'm closing this issue on my side. Maybe explaining this issue in official doc might help devs. We wasted weeks only to understand it. To Recap: Does your app send clear data and you don't need ios Communication Notification layout on iphone? Does your app send encrypted data or you need ios Communication Notification layout on iphone? Never use silent notifications on ios because they are throttled and cancelled most of time. This is why they don't work when app is terminated, it is not firebase_messaging issue, it is os that cancels them. Keep using silent notification on Android. This means duplicate data in your notification json (one for android using silent notification and one for ios using remote notification + mutableContent:1) |
Is there an existing issue for this?
Are you aware of the differences between iOS and Android background message handling?
Do you have an active Apple Developer account?
Are you using a physical iOS device to test background messages?
Have you enabled "Remote Notifications" & "Background Mode" (Checking options for "Background Processing" & "Remote Notifications") in your app's Xcode project?
Yes, pic below.
Have you created an APNs key in your Apple Developer account & uploaded this APNs key to your Firebase console?
Yes, pic below.
Have you disabled method swizzling for Firebase in your app?
Yes, pic below.
Are you sending messages to your app from the Firebase Admin SDK?
Yes, our code below:
admin
.messaging()
.send({
data: {...data, notificationType: 'chat'},
token: deviceToken,
android: {
priority: 'high',
data, // without it, badge is not displayed in foreground
},
apns: {
payload: {
aps: {
contentAvailable: true,
},
},
headers: {
'apns-push-type': 'background',
'apns-priority': '5', // Must be
5
whencontentAvailable
is set to true.'apns-topic': 'com.backend.presence', // bundle identifier
},
},
})
Have you requested permission from the user to receive notifications?
Have you used the 'Console' application on your macOS device to check if the iOS device's system is throttling your background messages?
From Console, we see that data-only notifications are always cancelled if app is terminated and user opens a different app.
"CANCELED: com.apple.pushLaunch.com.backend.presence:A680C5 at prioritv 5 !" (pic below).
As we wrote in #9300, our comment here #9300 (comment) ,
Apple told us that silent notifications on iOS are not meant to be used as on Android and we should use "notification" , which are never throttled and arrive quickly. Ofc, since most time content is encrypted, Apple provides the possibility to modify content (decrypt it) before displaying the badge. As mentioned, this is done by using "mutable-content:1" + a Service App Extension.
Additional context and comments
Hello and thanks for the investigation!
Our understanding is that firebase_messaging should integrate "notification" with "mutable-content:1" and "Service App Extension". Without this feature, it is not possible to use the plugin for apps that send high priority encrypted notifications (eg. financial or trading apps, chat and social media apps, banks apps). In these cases, app might send encrypted content that should be decrypted before displaying the badge.
Why we cannot use "data-only notification" as is it now?
Beyond the throttling, they don't work at all when "app is terminated and user opens another app". This is not a bug of firebase_messaging but Apple's policy.
Why we cannot use "notification" as it is now?
Because without mutable-content and Service App Extension, badges will be displayed before having the opportunity to decrypt notifications' content.
Hope this will be helpful.
The text was updated successfully, but these errors were encountered: