我使用的是带有Cordova的Firebase云消息。我想允许用户在应用程序设置中设置静默通知。
然而,我经常向整个主题订阅者推送通知,因此我不能为特定用户设置为静音。
我认为正确的方法是向fcm服务器发送http请求,并告诉他们这个特定的令牌应该接收静默通知。如果这是正确的方法。
我该怎么做?
In Service:-
token='key=AAAA7SRV_tKJ1NzRT8d2VJ5NGkayEx1HT9SxrdTT5G5a4kx5c6GoDvmWmzhCTWDRCqrdACrctF5Gjy5Df2qf6ZCNJHt7oHfH7BC'
createNotification(data) {
const headers = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': this.token
});
console.log('Res from Frontend=>', data)
return this.http.post('https://fcm.googleapis.com/fcm/send', data, { headers: headers }).subscribe(res => {
console.log('Res from APi', res)
})
}
In component.ts:-
const fcm = {
"notification": {
"title": '',
"body": '',
"sound": "default",
"click_action": "FCM_PLUGIN_ACTIVITY",
"icon": "./../../assets/images/logos/arabic-purpal-logo.png"
},
"data": {
"hello": "This is a Firebase Cloud Messagin hbhj g Device Gr new v Message!",
},
"to": 'FCM Token Here'
};
this.service.createNotification(fcm)
}
Note:- Put the token in string, it send only for that user only