I am new at mobile development and I choose React native, but I want to send remote push notification to a specific user. Can I use this library: react-native-push-notification ? there is a complete tutorial for that ?
3 Answers
Yes you can use this library https://github.com/evollu/react-native-fcm to connect your application with firebase, Then all you have to do is to log the device token that enable you to push notification for this device only with firebase
2 Comments
zedArt
Thanks for your answer. There is no tutorial for that ?
Hussam Kurd
The library Readme section describes how you can install it and include examples as well
You have to save the UUID of each user and then you can use axios to send push notification to those users.
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 }
}
}
}
I hope it helps you!
See google firebase documentation for more details: https://firebase.google.com/docs/cloud-messaging/http-server-ref
1 Comment
cccnrc
please contextualize more your answer, show a code example etc