2

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 3

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer. There is no tutorial for that ?
The library Readme section describes how you can install it and include examples as well
1

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

please contextualize more your answer, show a code example etc
0

Check react-native-firebase.
Section: Cloud Messaging.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.