React native Push notification Locally

Push notification is the feature notify user for any new update or send any message to user like whats app. There are two type of notifications.

1. Local push notification
2. Remote push notification

In this article we discuss about local notification. For remote notification needs (FCM) Firebase cloud messaging service. But many times we need to send notification locally. so this method is try to solve this problem. Follow these steps:

1. Install library for local notification
2. Get Firebase senderId from project settings
3. Set up code for send notification

1. Install library for local notification

First you need to install library in your react native project with this command:

2. Get Firebase senderId from project settings

After library installation we need senderId. this id you can generate from Firebase project setting. please follow these steps for get this senderid:

  1. Login into firebase console with help of this link https://console.firebase.google.com/.
  2. Now go to project setting under link check below image
  3.  Now click on cloud messaging there you can find this senderId

3. Setup code for local push notification

Before write the code for push notification you need add some lines in android/app/src/main/AndroidManifest.xml

Add this link in android/build.gradle

In android/app/build.gradle

Now you can create a component name with PushController.js and use this component in your parent component. This code trigger local notification automatically.

This code trigger notification instantly. but you can set its time when you need to trigger local notification with localNotificationSchedule function:

 

Add a Comment

Your email address will not be published. Required fields are marked *