flutterfire
flutterfire copied to clipboard
🐛 [firebase_messaging] can't disable foreground notification IOS
Bug report
Describe the bug I am using this function: await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( alert: false, badge: false, sound: false, );
to disable foreground notification in IOS but I'm keep getting the notification while app is in foreground.
Steps to reproduce
Steps to reproduce the behavior:
- Open the app.
- Send notification after setting foreground options
Expected behavior
Notification shouldn't be display.
Flutter doctor
Run flutter doctor
and paste the output below:
Click To Expand
[✓] Flutter (Channel stable, 3.7.11, on macOS 13.2.1 22D68 darwin-arm64, locale en-IL)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.3)
[✓] Connected device (4 available)
[✓] HTTP Host Availability
• No issues found!
Flutter dependencies
Run flutter pub deps -- --style=compact
and paste the output below:
Click To Expand
PASTE OUTPUT INSIDE HERE
Thanks for the report @ItayBarFaye Take a look at this issue and this comment and check if it helps in your case to resolve your issue.
Thanks for the report @ItayBarFaye Take a look at this issue and this comment and check if it helps in your case to resolve your issue.
Didn't see any solution only to use this function and it doesn't work..
Also removing notification object it's not a real fix cause IOS doesn't support silent push notification when app is terminated
Thanks for the feedback.
Can you provide a sample payload that you are sending ? Also please take a look at plugin example and see if using it, you get same behavior or not. Currently it is set to true
, but checking the behavior setting it to false
would help to analyze further.
{ "notificaion": { "body": "First Notification", "title": "ALT App Testing" }, "data": { "key_1": "Data for key one", "key_2": "Hellowww" }, "content_available": true, "priority": "high" }
Thanks for the update. I am going ahead and labeling this for team's attention and input on expected behavior.
Currently, per plugin example, it is set to true
. In order to set it to false
and then sending a notification seems to be showing up.
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: false,
badge: true,
sound: true,
);
Per documentation:
/// If all arguments are `false` or are omitted, a notification will not be displayed in the
/// foreground, however you will still receive events relating to the notification.
Future<void> setForegroundNotificationPresentationOptions({
bool alert = false,
bool badge = false,
bool sound = false,
however you will still receive events relating to the notification
maybe related ?
Yes, that right but this function doesn't work, I set everything to false and the os still presenting the notification.
Hi, I encountered the same issue, do we have updates now regarding this issue?
Hi, I encountered the same issue, do we have updates now regarding this issue?
Looks like no one been assigned to this issue, but I found a hack if it helps, I am sending two notification to IOS device: one with only data object and one with both (data and notification) with header "apns-push-type": "background"
Hey, What about this bug any updates?
I've also encountered this bug. The documentation says: "Important: The requested permissions and those set by the user take priority over these settings." which is kind of confusing. I assume it means the foreground notifications can't use alerts/badges/sounds if the permission for them was not requested. But you should still be able to NOT use them (specifically sound in my case) even though you theoretically have the permission to use them.
My use case is either disabling sound for them or disabling them completely so I can handle the foreground notification myself using the local_notification plugin. But neither is working at the moment.
I've just tested this extensively, it works as intended. I'm going to need a stripped down reproduction showing the bug.
FYI; onMessage
handler will still fire even when you set alert
to false like this:
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: false,
badge: true,
sound: true,
);
The notification displayed by the Firebase Messaging plugin is blocked from appearing.
My main issue was that I was not able to disable sound for foreground notifications, did you try that? So
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( alert: false, badge: true, sound: false, );
When receiving a notification in the foreground, it still played the sound.
Hey @ItayBarFaye. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Hey, sorry for the late reply.
I tested it again and it still didn't work which mean notification still been presented on foreground. The notification's payload is with notification object contain title and body, and also data object contain type.
Call in init: await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( alert: false, badge: false, sound: false, );
Sending push notification - Expected: Notification shouldn't be displayed. Actual: Notification displayed
Thanks again.
Hey folks,
The issue is still exist, this limitation is introducing unwanted behaviour to the user experience, not really sure how this behaviour can be resolved!
Any update would be great! @darshankawar
Hello,
we are having the same problem .. seeing native push notifications in foreground .. can anyone help us?
have you solved the issue?
I've just tested this extensively, it works as intended. I'm going to need a stripped down reproduction showing the bug.
FYI;
onMessage
handler will still fire even when you setalert
to false like this:await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( alert: false, badge: true, sound: true, );
The notification displayed by the Firebase Messaging plugin is blocked from appearing.
@russellwheatley brought here from @darshankawar. As mentioned in my issue https://github.com/firebase/flutterfire/issues/12015#issuecomment-1849951692
we can prevent the notification banner from showing up by setting alert:false
. However, this is conflicting with FlutterLocalNotifications plugin and all other local notification banners wont be displayed anymore.
To reproduce this:
-
Set
alert:false
-
Send a payload with the json from here https://github.com/firebase/flutterfire/issues/12015#issuecomment-1849951692
-
Try to display a fake local notification via flutter local notication plugin.
setForegroundNotificationPresentationOptions
impacts this other plugin and alert wont be displayed.
Im wondering whether this is the expected result, coz I think alert:false
blocks the system from showing banners, that will ofc impact flutter local notification, which displays its banner via native.
We are having this problem on android. If app is in background the alert is displayed even if alert:false
did you find a solution ???
i wanna show just local notif in terminated state and background state, if i put local notif when recive FCM ,the notif shwed twice , i should handel the click of the call notif in terminated state to navigate to call screen
Hi, we are also facing the same problem, does anyone have solution or hack to resolve this ? This is getting blocker for us. any help much appricated.
Hi @darshankawar, Could you please provide an update on this issue? It's becoming a blocker for us, and your contribution would be greatly appreciated. Thanks in advance for your help. CC: @premjangir344 , [email protected]
Hi everyone,
I identified the root cause of the issue. We were using the https://pub.dev/packages/awesome_notifications library to show notifications, but it was causing problems. I'm not sure what the specific issue with the library is, but once we removed it, everything started working perfectly. We have switched to using flutter_local_notifications for notifications, and it is working flawlessly. I request all to please check if you are using awesome_notifications if yes then replace it with flutter_local_notifications.
Thanks Yogesh Kumar Elevn
Hi everyone,
I identified the root cause of the issue. We were using the pub.dev/packages/awesome_notifications library to show notifications, but it was causing problems. I'm not sure what the specific issue with the library is, but once we removed it, everything started working perfectly. We have switched to using flutter_local_notifications for notifications, and it is working flawlessly. I request all to please check if you are using awesome_notifications if yes then replace it with flutter_local_notifications.
Thanks Yogesh Kumar Elevn
@ItayBarFaye - are you using awesome notifications? or another notifications package that could be changing the settings?
@russellwheatley Hey, actually no I'm using only flutter_local_notifications and firebase_messaging
Have you tried without that package to see if it changes the behaviour?
No, because I need it.