我在 iOS 应用程序中使用 Firebase 推送通知。尽管我可以通过发送以下有效负载来发送通知,但它在收到时不会播放声音。
{
"to": "myToken",
"notification": {
"body": "test",
"title": "test"
},
"priority": "high"
"sound": "default"
}
如果我从控制台发送测试消息,它运行良好并播放通知声音。
注:
https://fcm.googleapis.com/fcm/send
您的 JSON
"sound" : "default"
应位于 "notification"
键内,而不是位于 JSON 的根目录中。这个 JSON 应该可以工作。
{
"to": "myToken",
"notification": {
"body": "test",
"title": "test",
"sound": "default"
},
"priority": "high"
}
使用FCM admin SDK时,您必须分别为Android和Apple设备指定声音:
let message = {
notification: {
'body': 'This is the message the user sees',
},
data: {
'param1': 'specify some extra data here',
},
// Apple specific settings
apns: {
headers: {
'apns-priority': '10',
},
payload: {
aps: {
sound: 'default',
}
},
},
android: {
priority: 'high',
notification: {
sound: 'default',
}
},
token: 'target FCM token goes here',
};
(注意:到目前为止我只测试了Apple设置)
payload = {
notification:{
title: 'SOLO has been changed by an administrator',
body: 'Administrator changed your SOLO schedule',
},
android: {
},
apns: {
headers:{
"apns-collapse-id": "solo_changed_administrator",
"content-available": "1",
"apns-priority": "10",
},
payload:{
aps:{
sound: 'default',
badge: 12213123223
}
}
},
data:{
type: 'type'
}
}
https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#ApnsConfig
我也有同样的问题。当通知通过 FCM 发送到 iOS 时,无法发出声音或振动。我在这里点击了这个链接:https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW1 并最终成功了。我在我的有效负载中创建了我的苹果通知作为警报,它对我有用。下面是我的 JSON,以了解我的解决方案。
"apns": {
"payload": {
"aps" : {
"alert" : {
"body": "Notification body",
"title": "Notification title"
},
"badge" : 2,
"sound" : "default"
}
}
}
注意:请将此“apns”键放在您的消息请求的相关位置。我正在使用 REST 调用来请求消息。 请参阅以下链接,了解如何使用特定于平台的传递选项发送通知消息。 链接:https://firebase.google.com/docs/cloud-messaging/concept-options#example-notification-message-with-platform-specific-delivery-options
使用
firebase-admin
节点 js 包
const message = {
notification: {
title: "This is title",
body: "This is body",
},
apns: {
headers: {
"apns-priority": "10",
},
payload: {
aps: {
sound: "default",
},
},
},
android: {
notification: {
sound: "default",
},
},
token: 'fcm-token'
}
getMessaging()
.send(message)
.then((response) => {
res.json({
msg: "Sent successfully",
});
console.log(response);
})
.catch((err) => console.log(err));