离子 2 - FCM 自定义声音通知



我已经使用 PHP 实现了 FCM 通知,以便在移动设备上发送通知。 通知工作正常,但我想为通知添加声音。 我遵循了 FCM 的 Ionic 文档。

this.fcm.getToken().then(token =>{
alert("token : "+token);
});
this.fcm.onNotification().subscribe(data => {
alert("data :"+ JSON.stringify(data));
if(data.wasTapped){
alert("Received in background : "+ JSON.stringify(data.msg));
} else {
alert("Received in foreground : "+ JSON.stringify(data.msg));
}
}, err =>{
alert("Received err : "+ err);
})

我的 php 有效负载:

$message['msg'] = 'notification text';
$message['sound'] = 1;
$message['vibrate'] = 1;
$fields = array(
'registration_ids' => $tokenIds,
'data' => array('message' => $message)
);

我正在向通知插件发送$fields

有人实现过这种功能吗?

在推送通知有效负载中设置以下属性。 您需要将sound属性设置为default

"notification":{
"title":"Notification title",
"body":"Notification body",
"sound":"default",
"click_action":"FCM_PLUGIN_ACTIVITY",
"icon":"fcm_push_icon"
},

在 php 服务器端,我像这样设置$fields数组

$fields = array(
'registration_ids' => $tokenIds,
'data' => array('message' => $message,
'click_action' => "FCM_PLUGIN_ACTIVITY",
'sound'=>'default'),
'notification'=>array('message' => $message,
'click_action' => "FCM_PLUGIN_ACTIVITY",
'sound'=>'default'),
'priority'=> "high"
);

这可以用于背景中的FCM通知和Ionic中的声音

最新更新