使用 flutter firebase_messaging 插件发送通知声音 [英] Sending notification sound with flutter firebase_messaging plugin

查看:43
本文介绍了使用 flutter firebase_messaging 插件发送通知声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的应用程序向用户发送通知,该通知将使用默认通知声音提醒他们.

I am trying to get my application to send a notification to a user which will alert them with their default notification sound.

到目前为止,我正在使用插件 firebase_messaging 和以下代码:

So far, I am using the plugin firebase_messaging with the following code:

Message firebaseMessage = Message()
..to = token
..body = body
..title = title;
firebaseCloudMessage.send(firebaseMessage);

这允许我向选定的用户发送通知并将其显示在他们的主屏幕上.唯一的问题是,它不会在 iOS 上播放声音,也不会在传递通知时为 Apple Watch 提供触感.

This allows me to send a notification to a selected user and display it on their home screen. The only problem is, it does not play a sound on iOS or give Apple Watch haptics when the notification is delivered.

如何使用 firebase_messaging 框架播放声音?

How can I play a sound using the firebase_messaging framework?

如果有帮助,这是我的配置:

If it helps, here is my configuration:

_firebaseMessaging.requestNotificationPermissions(
  IosNotificationSettings(
    sound: true,
    badge: true,
    alert: true
  )
);

如果我直接从 firebase 发送消息并在选项中启用声音,声音和触觉就会起作用,我就是不知道如何使用这个框架来做到这一点.

Sounds and haptics work if I send a message directly from firebase and enable sounds in the options, I just can't work out how to do it with this framework.

推荐答案

也许为时已晚.但是我一直在为 iOS 中的通知声音而苦恼.问题是我使用 Firebase 发送通知并且它使用最新的 API,所以我不得不添加apns"参与通知消息:

Maybe it is too late. But I have struggled with notification sound in iOS. The problem was I was using Firebase to send the notification and it uses the latest API, so I had to add the "apns" part in the notification meassage:

     const payload = {
                      notification: {
                          title: "title",
                          body: "message",

                      },
                      data: {
                          info: "any data",
                          click_action: "FLUTTER_NOTIFICATION_CLICK",
                        },
                      apns:{
                        payload:{
                            aps:{
                             sound:"default"
                            }
                        }
                     },
                      condition:condition //if using topics
                 };

这篇关于使用 flutter firebase_messaging 插件发送通知声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆