feat(messaging): add config option whether notification should be displayed in the foreground
Discussed in https://github.com/capawesome-team/capacitor-firebase/discussions/397
Is there any existing functionality to disable notifications when the app is open and instead use an in-app notification?
Solving this problem without the use of the local notifications and directly within the capacitor-firebase/messaging package would be a cool feature!
What is the status looking like on this? Would be great if this could be implemented soon. We have a chat app and if two people are chatting at the same time it's pretty annoying to also get a push notification on every message.
Great package otherwise, thanks for all the hard work!
@timmyrosen This PR is intended to ensure that you also receive push notifications on Android in the foreground. I think you are looking for the opposite (probably for iOS).
That's what I am looking for. Any way to disable notifications when the app is in foreground on iOS.
@tomek-em Got it!
What is the status looking like on this?
PRs are welcome!
Following.
I've just noticed that it's already possible to configure whether a notification should be shown if the app is in the foreground on iOS using the presentationOptions configuration option. You just have to set an empty array:
{
"plugins": {
"FirebaseMessaging": {
"presentationOptions": []
}
}
}
I'm therefore closing this issue.
This was previously asked here
@robingenz I'm not sure if this is the right place to ask. But is it also intended that the requestPermission() will automatically return 'denied' when you have no presentationOptions configured? I would still like to show the permission prompt even when I don't show the notifications in the foreground.
And you replied:
@roosalyn Yes, this is intended. If no presentation options are defined, you do not need any permissions. If you have more questions, please create a discussion.
"presentationOptions": [] is effectively unusable in such case, because with that setting we get no notifications, be it background or foreground. The documentation is misleading as its behavior is to immediately deny the request just as you stated in the other thread. What is really needed is the behavior in the documentation. So effectively an empty array should result in no action in the app when it is in the foreground, and the requests for permission should not be automatically rejected with "denied", but the app should ask the user for the permission instead. If user gives permission, that should mean the app could get notifications in the background only as defined in apns.payload.aps key in the message body.
As a side note, I think the empty array option was working as intended (conforming to the documentation) about 2 years ago, if I remember correctly. The behavior of immediate denial must have been added sometime later. I wrote this with the hope that it could help track the issue somewhere in commit history.
@egemadra Yes, you're right. Seems like this PR has broken it: https://github.com/capawesome-team/capacitor-firebase/commit/2085bb84414a9a74f8d5587b61e8391ff4598a8c. This will be fixed in the next release, see https://github.com/capawesome-team/capacitor-firebase/pull/826.