【发布时间】:2020-09-08 11:14:03
【问题描述】:
我是移动开发新手,我选择 React native,但我想向特定用户发送远程推送通知。我可以使用这个库: react-native-push-notification 吗?有完整的教程吗?
【问题讨论】:
标签: react-native push-notification
我是移动开发新手,我选择 React native,但我想向特定用户发送远程推送通知。我可以使用这个库: react-native-push-notification 吗?有完整的教程吗?
【问题讨论】:
标签: react-native push-notification
是的,您可以使用这个库 https://github.com/evollu/react-native-fcm 将您的应用程序与 firebase 连接,然后您所要做的就是记录设备令牌,使您能够仅使用 firebase 推送此设备的通知
【讨论】:
您必须保存每个用户的 UUID,然后您可以使用 axios 向这些用户发送推送通知。
export const sendNotificationFirebaseAPI = async (
token: string,
title: string,
body: string,
data?: object,
) => {
if (token != '') {
const headers = {
Authorization: `key=${GOOGLE_FCM_KEY}`,
'Content-Type': 'application/json',
}
const bodyToSend = JSON.stringify({
to: token,
notification: {
title,
body,
},
data,
})
try {
await axios({
method: 'post',
url: 'https://fcm.googleapis.com/fcm/send',
headers: headers,
data: bodyToSend,
})
} catch (err) {
return { err }
}
}
}
希望对你有帮助!
有关详细信息,请参阅 google firebase 文档:https://firebase.google.com/docs/cloud-messaging/http-server-ref
【讨论】: