在react native中从客户端站点发送firebase推送通知的最简单方法



我是新来的本地react,我一直在从客户端发送推送通知。我有每个用户的FCM令牌,但需要向特定用户发送通知。如果你想更清楚,请评论并让我知道这个的解决方案

我看到了你的问题,我有一个解决方案。我已经在做了,这是我的代码。

export const sendPushNotification = async (token, title, body,) => {
//console.log("token==>", token);
const FIREBASE_API_KEY ="<your firebase cloud messaging server key>"
const message = {
registration_ids: [token],
notification: {
title: title,
body: body,
vibrate: 1,
sound: 1,
show_in_foreground: true,
priority: "high",
content_available: true
},
};
let headers = new Headers({
"Content-Type": "application/json",
Authorization: "key=" + FIREBASE_API_KEY
});
let response = await fetch("https://fcm.googleapis.com/fcm/send", {
method: "POST",
headers,
body: JSON.stringify(message)
});
// console.log("=><*", response);
response = await response.json();
//  console.log("=><*", response);
};

你可以像这个一样使用这个功能

sendPushNotification(
FCMToken,
'title of message',
`this is body of message`,
);

希望它对你方有效

最新更新