Part 3: Set Up the Google Firebase Cloud Messaging Server
Introduction
You can use Google’s Firebase Cloud Messaging (FCM) service to send push notifications to both Android and iOS devices. To send push notifications using FCM from the Push Notifications Connector module, you must set up a Firebase account with FCM enabled. This section teaches you how to register for FCM and configure the service in your app.
Prerequisites
Before starting this section, make sure you have completed the following prerequisites:
- Have a Firebase account (https://firebase.google.com)
Setting Up a Firebase Project
There are two possible scenarios: you can create a new FCM project, or you can update your existing GCM project to FCM. Both scenarios are described below.
Migrating a GCM project to FCM
To prevent the degraded reliability of push notifications delivery, you should migrate existing GCM projects to FCM and upgrade credentials if needed.
Signing into the Developer’s Console
Open the Firebase developer’s console and sign in with your Google ID.
Importing the Project
To import your project, do the following:
-
In the Firebase console, select Import Google Project.
-
Select your GCM project from the list of existing projects, select a region, and click Add Firebase:
With that done, continue with Configuring APNs Credentials below.
Creating a New FCM Project
Signing into the Developers Console
Open up the Firebase developers console and sign in with your Google ID.
Creating the Project
To create a project, do the following:
-
Click Create new project.
-
Fill in your application’s project name and region.
-
Click Create"
Adding an App
Before you add a native app to FCM, you must retrieve your app’s bundle ID. Its location depends on your type of your mobile app. This is not needed for a progressive web app.
For a native mobile app, your bundle ID will be what you specify for the App identifier in the NBUI. You can find this ID later in your generated GitHub repo:
- For Android, open android/app/build.gradle and consult applicationId to find your ID
- For iOS, open ios/Config/config.xcconfig and consult BUNDLE_IDENTIFIER to find your ID
Click Deploy, then Mobile App. Your ID is listed as App Identifier:
Do the following to add your app to FCM:
-
Click the Project Overview cogwheel and select Project settings:
-
Go to the General tab and click on your target platform (iOS, Android, or Web) in the section Your apps:
-
Fill in the bundle_id (only for iOS and Android), an app nickname of your choice, and skip the rest of the steps:
Bundle ID must be matching with your package ID. Make sure to repeat this step for iOS as well.
Configuring APNs Credentials (Optional)
If you wish to send push notifications to iOS devices through FCM (for native mobile apps), you will need to configure your APNs credentials:
-
Click in the upper-left corner of the screen and select Project settings.
-
Navigate to the Cloud messaging tab:
-
On this tab, upload either your APNs key or your APNs certificate(s) as configured in your Apple Developer account.
Setting Up a Service Account
In the upper-left corner of the screen, click the cogwheel and select Project settings. Then navigate to the Service accounts tab.
On this page, press Generate new private key. Store the resulting file in a secure location. You will use this file when configuring FCM in the back-end of your Mendix application.
The file you just created gives API access to all available Firebase services for your app. If you want a more restrictive service account, click Manage all service accounts in the upper-right side of the screen, then create a service account that is restricted to using the Cloud Messaging functionality.
Downloading the Google Services Config Files
In addition to the back-end configuration set up in the previous steps, you will need additional files that will be bundled as part of your native mobile application. For progressive web apps, you can skip this step. To obtain these, again click the cogwheel on the upper-left side of the screen and select Project settings. Then navigate to the General tab:
The list at the bottom shows the Android and iOS applications that you have configured for your Firebase project. Select the Android application and click google-services.json. Then click the iOS application and click GoogleService-Info.plist. Store both files in a secure location. You will need these when building your mobile application.
Copy the PWA Configuration
For progressive web apps, a configuration object is required to set up notifications in the web client. You can skip this step for native mobile apps. To obtain the configuration, again click the cogwheel on the upper-left side of the screen and select Project settings. Then navigate to the General tab and click on Config:
Copy the text that is highlighted in the screenshot above and store it somewhere safe. You will need this text in a later step.
Set up Web Push Certificate
For progressive web apps, an additional certificate is needed. You can skip this step for native mobile apps. To generate the certificate and obtain its public key, again click the cogwheel on the upper-left side of the screen and select Project settings. Then navigate to the Cloud Messaging tab and click on Generate Key Pair:
After generating the certificate, copy the certificate that is highlighted in the screenshot below and store it in a safe place. You will need this certificate in a later step.