Migrate from GCM to FCM for Push Notification In React Native

Migrate from GCM to FCM for Push Notification In React Native

Tudip

Tudip

05 June 2019

Hello folks as you may know Google has removed GCM service support from 11th April 2019. Hence, all the projects which are using GCM service need to be migrated to FCM. FCM (Firebase Cloud Messaging) is introduced by Google to replace GCM (Google Cloud Messaging) as FCM provides more innovative tools the GCM.

GCM to FCM Migration

Migrate

As React native is used for hybrid application development, we use packages/library which are already developed for push notification. Hence, it necessary that library you are using also supports FCM migration. Considering for IOS you might be using APNS this blog will cover migration for Android part.

Following steps need to be followed in order to migrate to FCM

Step 1: In Order to migrate from GCM to FCM, it is necessary to have Firebase account which can be created on https://console.firebase.google.com. Create a project on Firebase console using your registered email id:

Step 2: Supply a project name, accept terms & conditions and then click on Create Project button.

Step 3: At Firebase console under Get started by adding Firebase to your app click on android icon to get started.

Step 4: Provide your package name and SHA-1, and select Add App. Download the google-services.json file required for the app.

Step 5: Select Project settings by clicking on gear icon:

Step 6: Click on Cloud Messaging tab under project settings. You will find your Sender Id and Server key.

Step 7: Replace FCM Server key with GCM API key at you server side in order to receive push notification from FCM.

Step 8: In Order to receive push notification at client side it is necessary to configure app with FCM. Replace your existing GCM sender ID with FCM sender ID in your code.

Step 9: At app-level build.gradle switch to FCM:

Before:

dependencies { compile “com.google.android.gms:play-services-gcm:16.0.0” }

After:

dependencies { compile “com.google.firebase:firebase-messaging:17.3.4” }

 

Step 10: Edit App’s manifest by removing GCM configuration code with FCM part:

GCM:

<uses-permission android:name=”android.permission.WAKE_LOCK” /> <permission android:name=”<your-package-name>.permission.C2D_MESSAGE” android:protectionLevel=”signature” /> <uses-permission android:name=”<your-package-name>.permission.C2D_MESSAGE” /> <receiver android:name=”com.google.android.gms.gcm.GcmReceiver” android:exported=”true” android:permission=”com.google.android.c2dm.permission.SEND” > <intent-filter> <action android:name=”com.google.android.c2dm.intent.RECEIVE” /> <category android:name=”com.example.gcm” /> </intent-filter> </receiver>

FCM:

<service android:name=“.java.MyFirebaseMessagingService”> <intent-filter> <action android:name=“com.google.firebase.MESSAGING_EVENT” /> </intent-filter> </service>

Conclusion

Once all the above steps are followed you are good to go for receiving push notification using FCM.

search

Blog Categories

Request a quote