Firebase Messaging
Step 5: FCM integration
5.1 Steps for Host Apps with no current FCM integration
If your project already has a google-services.json file, please skip to 5.2 . If not please follow one of the options below
5.1.1 Set up Google Play Services project if one does not exist
Create a firebase project & app in Google Firebase console representing your app and add the corresponding google-services.json to the directory. To do this please visit https://console.firebase.google.com/ and follow the steps to:
(a) Add a project
(b) Add an app to the project
(c)Download google-services.json
(d) Add to the project folder <project-root>\platforms\android\
5.1.2 Set up Google Play Services project if one does not exist
We need to integrate the FCM plugin before we proceed to next steps. Follow the below steps would help you with it.
- Open the project root folder in command prompt / Terminal
- Execute the command
$ ionic cordova plugin add cordova-plugin-fcm-with-dependecy-updated
$ npm install @ionic-native/fcm
- Post adding this you will be able to test push the FCM messages from Firebase Console.
5.2 Steps for Host Apps with existing FCM implementation
Follow these steps if your application has Firebase Cloud Messaging (FCM). If not you can skip this section.
5.2.1 : Token Integration
Open your Java file that extends the FirebaseMessagingService. Add the following code to the onNewToken method.
public void onNewToken(String s) {
super.onNewToken(s);
// BEGIN: Add code to refresh IU Token.
IUApp.refreshFCMToken(this);
// END
}
5.2.2 : Message Handling
Enable IU to handle FCM Messages if the sender is IU. Use the following code in the onMessageReceived method.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// BEGIN: Enable IU to handle messages targeted for IU
// Add the below line on 1st line of the method.
if(IUApp.handleFCMMessage(this, remoteMessage)) {
return;
}
// END
// Continue code for Host Apps.
}
5.3 Configure IU Server for the Host APP
IU Server needs to do minimal configuration corresponding to Host app to connect to host app via FCM, Please provide package name of the Host app to IU.
Step 6: Configure IU Server for the Host APP
DR Server needs to do minimal configuration corresponding to Host app to connect to host app via FCM, Please provide package name of the Host app to DR.
Updated almost 3 years ago