firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.46k stars 3.91k forks source link

🐛 [firebase_messaging] can't disable foreground notification IOS #10804

Open ItayBarFaye opened 1 year ago

ItayBarFaye commented 1 year ago

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

darshankawar commented 1 year ago

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.

ItayBarFaye commented 1 year ago

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 commented 1 year ago

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

darshankawar commented 1 year ago

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.

ItayBarFaye commented 1 year ago

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

darshankawar commented 1 year ago

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 ?

ItayBarFaye commented 1 year ago

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

rsillador commented 1 year ago

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

ItayBarFaye commented 1 year ago

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 commented 10 months ago

Hey, What about this bug any updates?

Aulig commented 10 months ago

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.

russellwheatley commented 10 months ago

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.

Aulig commented 10 months ago

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.

google-oss-bot commented 9 months ago

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!

ItayBarFaye commented 9 months ago

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.

khaled-gymerz commented 9 months ago

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

SerdarNur commented 6 months ago

Hello,

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

AbdullahGaber commented 5 months ago

have you solved the issue?

delfme commented 5 months ago

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 commented 5 months ago

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.

iosephmagno commented 4 months ago

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

haninhn commented 3 months ago

did you find a solution ???

haninhn commented 3 months ago

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

yogeshelevn commented 2 weeks ago

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 commented 2 weeks ago

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 , shivi@elevncommunity.com

yogeshelevn commented 1 week ago

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

russellwheatley commented 1 week ago

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?

ItayBarFaye commented 1 week ago

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

russellwheatley commented 1 week ago

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

ItayBarFaye commented 1 week ago

No, because I need it.

google-oss-bot commented 3 days ago

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!

Mohammedqwasmeh commented 1 day ago

Hey I am facing this issue too please dont close it