Closed sinanverve7 closed 3 months ago
I am closing this issue as this is the intended behavior and not a bug.
Hi @robingenz so if i didnot give "sound" as a parameter in presentationOptions like below, will it mute both foreground and background notification? i were trying to migrate from capacitor-pushnotification to handle silent notification in ios. previously only our background notification used to come up with sound. FirebaseMessaging: { presentationOptions: [], },
hi @robingenz in my case it silences the background notification aswell.? it is opposite to the intended behaviour.
I misread your issue.
so if i didnot give "sound" as a parameter in presentationOptions like below, will it mute both foreground and background notification?
No, this only affects the foreground. I have just tested it and had no problems. Make sure you set the sound
property when sending the notification. Here is my nodejs code that I tested it with:
import { initializeApp, cert } from "firebase-admin/app";
import { Message, getMessaging } from "firebase-admin/messaging";
initializeApp({
credential: cert("<PATH>"),
});
// This FCM token comes from the Capacitor Firebase Cloud Messaging plugin.
const token = "<TOKEN>";
const message: Message = {
notification: {
title: "Capacitor Firebase Messaging",
body: "Hello world!",
},
apns: {
payload: {
aps: {
sound: "default",
},
},
},
token: token,
};
// Send a message to the device corresponding to the provided FCM token
getMessaging()
.send(message)
.then((response) => {
console.log("Successfully sent message: ", response);
})
.catch((error) => {
console.log("Error sending message: ", error);
});
For more information, take a look at this Push Notification Guide for Capacitor.
i have checked above backend code with our backend dev.we tried with both legacy firebase api and new api in both cases sound is muted.in the presentation options only "sound" parameter seems to have issue.the same notification gives sound with @capacitor/push-notifications.is there any other cases that blocks sound associated with push-notification ?
{
"notification": {
"body": "",
"id": "value",
"title": "check your card",
"subtitle": "",
"data": {
"google.c.sender.id": "value",
"aps": {
"sound": "default",
"alert": {
"title": "check your card",
"body": ""
}
},
"gcm.notification.params": "value",
"google.c.fid": "value",
"google.c.a.e": "value",
"gcm.message_id": "value"
}
}
}
Have you tested it with the official demo app?
No i havenot tested yet
@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.
@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.
Plugin(s)
Version
5.4.1
Platform(s)
Current behavior
When configuring FirebaseMessaging's presentationOptions in my Capacitor app:
FirebaseMessaging: { presentationOptions: [], },
Conversely, including "sound" in presentationOptions (["sound"]) activates sound for both foreground and background notifications. This is problematic as it doesn't allow for silent handling of foreground notifications while ensuring background notifications are audible.
This configuration behavior does not allow for differentiated handling of notification sounds based on app state (foreground vs. background), limiting flexibility in notification management.
Expected behavior
Reproduction
https://github.com/sinanverve7/fcm-issue-reproduction
Steps to reproduce
Other information
i have integrated capacitor-firebase/authentication aswell ( 5.1.0 )
Capacitor doctor
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 5.7.4 @capacitor/core: 5.7.4 @capacitor/android: 5.7.4 @capacitor/ios: 5.7.4
Installed Dependencies:
@capacitor/android: not installed @capacitor/cli: 4.8.1 @capacitor/core: 4.8.1 @capacitor/ios: 4.8.1
[success] iOS looking great! 👌
Before submitting