Reputation: 487
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 ?
Upvotes: 2
Views: 6564
Reputation: 521
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
Upvotes: 1
Reputation: 9206
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
Upvotes: 1