【问题标题】:How to add custom notification sound - Ionic 4如何添加自定义通知声音 - Ionic 4
【发布时间】:2019-12-26 00:16:51
【问题描述】:

我将 FCM 插件与 Firebase 云消息传递一起使用。通过对使用设备令牌发送通知的 Cloud Function 进行 http 调用来发送通知。

云函数如下所示:

  let payload = {
            notification: {
                title: 'Pedido completado',
                body: 'Gracias por usar nuestro servicio!',
                sound: 'boop.mp3',
                priority: "high",
                icon: 'https://res.cloudinary.com/....Moviapp_icono_512x512.png'
            }
        };

admin.messaging().sendToDevice([token], payload);

我的 component.ts 是这样的

  async getToken(uid) {
    const token = await this.fcm.getToken();
    const body = { token, usuario: uid };
    this.sentTokenToTheServer(body);
  }

  async sendPushNotification(token) {
    const pushURL = `https://us...cloudfunctions.net/pushNotification?token=${token}`;
    this.http.get(pushURL, { responseType: 'text' }).toPromise();
  }

即使使用自定义图标,通知也能正常工作,但问题是默认情况下仍然存在声音

【问题讨论】:

    标签: android firebase ionic3 ionic4


    【解决方案1】:

    首先您需要在 src/assets 文件夹中添加您的 mp3 文件。然后将其添加到 config.xml 文件中

    <resource-file src="src/assets/boop.mp3" target="app/src/main/res/raw/boop.mp3" />
    

    那么通知负载应该是这样的

    {
      "notification":{
      "title":"Pedido completado",
      "body":"Gracias por usar nuestro servicio!",
      "sound":"boop.mp3",
      "click_action":"FCM_PLUGIN_ACTIVITY",
      "icon":"fcm_push_icon"
      }
    }
    

    【讨论】:

    • 你能告诉我ios的设置吗?在哪里存储声音以及如何存储?
    【解决方案2】:

    对于最新的 android 版本,如果您想使用自定义声音,则需要创建一个通知通道。 FCM 插件的文档描述了如何做到这一点。

    【讨论】:

      猜你喜欢
      • 2018-11-08
      • 1970-01-01
      • 1970-01-01
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 2016-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多