简体   繁体   中英

Ionic Capacitor - Push Notification not making sound on iOS

We're using this guide to create a pretty routine push notification system.

We have everything working and push notifications are coming through. On Android, the push notifications make the default alert sound. On iOS however, no sound is made.

How can we configure the push notification to use the default alert sound on iOS (we don't want to create/manage a custom alert sound).


I've already configured the presentationOptions setting in the capacitor.config.json file.

{
  "appId": "REDACTED",
  "appName": "REDACTED",
  "bundledWebRuntime": false,
  "npmClient": "npm",
  "webDir": "www",
  "plugins": {
    "PushNotifications": {
      "presentationOptions": ["badge", "sound", "alert"]
    }
  }
}

Push notifications appearance in foreground On iOS you can configure the way the push notifications are displayed when the app is in foreground by providing the presentationOptions in your capacitor.config.json as an Array of Strings you can combine.

Possible values are:

badge: badge count on the app icon is updated (default value) sound: the device will ring/vibrate when the push notification is received alert: the push notification is displayed in a native dialog An empty Array can be provided if none of the previous options are desired. pushNotificationReceived event will still be fired with the push notification information.

"plugins": {
  "PushNotifications": {
    "presentationOptions": ["badge", "sound", "alert"]
  }
}

push-notifications-appearance-in-foreground

What are you using to send the push notification?

I followed the same capacitor guide and faced the same issue, then I did a test by sending the notification from the Firebase Cloud Messaging console and it worked on iOS (the notification made a sound).

I found later that in the code I was using to send the notification (the firebase nodejs admin SDK), I didn't provide a value for the sound attribute. I assumed that since it's not required and it worked on Android, it should also work on iOS. I was wrong!

import * as admin from 'firebase-admin';

const message: admin.messaging.MessagingPayload = {
    data: {
        ...
    },
    notification: {
        title: 'title',
        body: 'body',
        sound: 'default' // Add this line
    },
};
await admin.messaging().sendToDevice(tokens, message);

The docs says that this attribute is only for the Android platform, which is why I didn't set it at first.


PS: I also added the presentationOptions setting mentioned above in the capacitor.config.json file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM