简体   繁体   English

离子电容器 - 推送通知在 iOS 上没有声音

[英]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.在 Android 上,推送通知会发出默认警报声。 On iOS however, no sound is made.然而,在 iOS 上,没有声音。

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).我们如何配置推送通知以使用 iOS 上的默认警报声音(我们不想创建/管理自定义警报声音)。


I've already configured the presentationOptions setting in the capacitor.config.json file.我已经在capacitor.config.json文件中配置了presentationOptions设置。

{
  "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.在前台显示推送通知 在 iOS 上,您可以通过在您的电容器.config.json 中提供presentationOptions 作为您可以组合的字符串数组来配置当应用程序处于前台时推送通知的显示方式。

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. pushNotificationReceived 事件仍将与推送通知信息一起触发。

"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).我遵循了相同的电容器指南并遇到了同样的问题,然后我通过从 Firebase 云消息传递控制台发送通知进行了测试,它在 iOS 上运行(通知发出声音)。

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.后来我发现在我用来发送通知的代码(firebase nodejs admin SDK)中,我没有提供sound属性的值。 I assumed that since it's not required and it worked on Android, it should also work on iOS.我认为,因为它不是必需的,并且可以在 Android 上运行,所以它也应该可以在 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. 文档说这个属性只针对Android平台,所以我一开始没有设置。


PS: I also added the presentationOptions setting mentioned above in the capacitor.config.json file. PS:我还在capacitor.config.json文件中添加了上面提到的presentationOptions设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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