I'm working on a Capacitor app and using @capacitor-firebase/messaging for push notifications.
My expected output is: I want to show background notifications with sound and handle foreground notifications using the "notificationReceived" listener to schedule a local notification, but only on specific screens.
My app had same functionality using @capacitor/push-notifications since it is not supporing silent notification iam trying to migrate from the plugin.
Here's what I've tried so far:
When I set presentationOptions to an empty array like this:
FirebaseMessaging: {
presentationOptions: [],
},
I get no sound for both foreground and background notifications.
If I include "sound" in presentationOptions like this:
FirebaseMessaging: {
presentationOptions: ["sound"],
},
Now, both foreground and background notifications make a sound.
My question is: How can I configure presentationOptions or use another method to allow sound for background notifications while keeping foreground notifications silent?
my whole capacitor.config.ts file is given below
import { CapacitorConfig } from "@capacitor/cli";
const config: CapacitorConfig = {
appId: "com.myapp",
appName: "myapp",
webDir: "www",
bundledWebRuntime: false,
plugins: {
FirebaseAuthentication: {
skipNativeAuth: false,
providers: ["phone"],
},
FirebaseMessaging: {
presentationOptions: [],
},
},
server: {
hostname: "myapp.in",
androidScheme: "https",
allowNavigation: ["myapp.in"],
},
ios: {
cordovaLinkerFlags: ["-ObjC"],
},
};
export default config;