flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [firebase_messaging] can't disable foreground notification IOS

Open ItayBarFaye opened this issue 1 year ago • 25 comments

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:

  1. Open the app.
  2. 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

ItayBarFaye avatar Apr 17 '23 14:04 ItayBarFaye

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.

darshankawar avatar Apr 18 '23 10:04 darshankawar

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..

ItayBarFaye avatar Apr 18 '23 11:04 ItayBarFaye

Also removing notification object it's not a real fix cause IOS doesn't support silent push notification when app is terminated

ItayBarFaye avatar Apr 18 '23 13:04 ItayBarFaye

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.

darshankawar avatar Apr 19 '23 10:04 darshankawar

{ "notificaion": { "body": "First Notification", "title": "ALT App Testing" }, "data": { "key_1": "Data for key one", "key_2": "Hellowww" }, "content_available": true, "priority": "high" }

ItayBarFaye avatar Apr 19 '23 10:04 ItayBarFaye

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 ?

darshankawar avatar Apr 19 '23 10:04 darshankawar

Yes, that right but this function doesn't work, I set everything to false and the os still presenting the notification.

ItayBarFaye avatar Apr 19 '23 11:04 ItayBarFaye

Hi, I encountered the same issue, do we have updates now regarding this issue?

rsillador avatar May 10 '23 05:05 rsillador

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"

ItayBarFaye avatar May 10 '23 06:05 ItayBarFaye

Hey, What about this bug any updates?

ItayBarFaye avatar Jul 16 '23 09:07 ItayBarFaye

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.

Aulig avatar Jul 22 '23 11:07 Aulig

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.

russellwheatley avatar Aug 02 '23 12:08 russellwheatley

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.

Aulig avatar Aug 02 '23 13:08 Aulig

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!

google-oss-bot avatar Aug 11 '23 01:08 google-oss-bot

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.

ItayBarFaye avatar Aug 16 '23 06:08 ItayBarFaye

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

khaled-gymerz avatar Sep 03 '23 11:09 khaled-gymerz

Hello,

we are having the same problem .. seeing native push notifications in foreground .. can anyone help us?

SerdarNur avatar Nov 10 '23 11:11 SerdarNur

have you solved the issue?

AbdullahGaber avatar Dec 10 '23 07:12 AbdullahGaber

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.

@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:

  1. Set alert:false

  2. Send a payload with the json from here https://github.com/firebase/flutterfire/issues/12015#issuecomment-1849951692

  3. Try to display a fake local notification via flutter local notication plugin. setForegroundNotificationPresentationOptions impacts this other plugin and alert wont be displayed.

delfme avatar Dec 11 '23 12:12 delfme

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.

delfme avatar Dec 11 '23 12:12 delfme

We are having this problem on android. If app is in background the alert is displayed even if alert:false

iosephmagno avatar Jan 24 '24 17:01 iosephmagno

did you find a solution ???

haninhn avatar Feb 26 '24 11:02 haninhn

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

haninhn avatar Feb 26 '24 11:02 haninhn

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.

yogeshelevn avatar May 15 '24 09:05 yogeshelevn

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]

yogeshelevn avatar May 16 '24 11:05 yogeshelevn

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

yogeshelevn avatar May 21 '24 09:05 yogeshelevn

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 avatar May 21 '24 10:05 russellwheatley

@russellwheatley Hey, actually no I'm using only flutter_local_notifications and firebase_messaging

ItayBarFaye avatar May 21 '24 11:05 ItayBarFaye

Have you tried without that package to see if it changes the behaviour?

russellwheatley avatar May 21 '24 11:05 russellwheatley

No, because I need it.

ItayBarFaye avatar May 21 '24 12:05 ItayBarFaye