Set Up Remote Notifications

Last update: Edit

1 Introduction

Remote push notifications allow you to remotely trigger small text messages, sounds, and more on your users’ devices. For more information on notifications, see Apple’s APNs Overview or Google’s Notifications Overview.

Native remote push notifications have the more capabilities than hybrid push notifications. Native push notifications also require a unique setup method:

  1. Generate an app using the Native Builder.
  2. Configure your Firebase setup.
  3. Customize your native template.

Follow the sections below to complete these three tasks and enable native remote push notifications. After you have completed this document, see How To Use Native Push Notifications for instructions on implementing native push notifications.

If you want to use local push notifications with the Make It Native app, the only step you have to perform is Setting up Firebase Cloud Messaging Service

This how-to will teach you how to do the following:

  • Customize your native template so it can use remote push notifications

2 Prerequisites

Before starting this how-to, make sure you have completed the following prerequisites:

3 Setting up Firebase Cloud Messaging Service

Google’s Firebase service supports both Android and Apple push notifications. Because APNs can require more work during customization steps, this document will teach you to set up your push notifications using Firebase.

To set up the Firebase cloud messaging server, complete How to Set Up the Google Firebase Cloud Messaging Server. During that document’s Adding an Android and iOS App section, be sure to add both an iOS and an Android app to your Firebase configuration. After you complete that tutorial, you will have these files:

  • google-services.json
  • GoogleService-Info.plist
  • yourPrivateKey.json

You will use these later to complete your work with the Native Builder and with Firebase.

4 Setting up Native App Customizations

After you create your app using the Native Builder’s prepare command, the Native Builder will create iOS and Android source code. To enable push notifications, you will customize these platforms’ source code files. The easiest way for your to customize these source code files is to follow the Implementing Push Changes With the Native Builder section below. If you wish to implement the changes manually, please skip to section Manually Implementing Changes section further below.

Choose one of these sections and complete only that section before moving on to Customizing the Android Manifest File.

4.1 Implementing Push Changes With the Native Builder

Remember these parameters of your app, since you will use them often in commands (for more information on parameters, see the Native Builder Reference Guide):

  • --project-name
  • --mendix-version
  • --github-access-token

Also, be sure to remember the absolute path to your app’s google-services.json and GoogleService-Info.plist files.

Run these commands in any order:

./native-builder.exe config ios add-entitlements --project-name "your project name" --entitlements notification
./native-builder.exe config ios add-background-modes --project-name "your project name" --modes notification
./native-builder.exe prepare --github-access-token yourAccessToken12345 --projectName "your project name"  --mendix-version x.x.x --firebase-ios-config-path A:\\bsolute-Path-To\GoogleService-Info.plist --firebase-android-config-path A:\\bsolute-Path-To\google-services.json

These commands will automatically do the necessary code alterations and make a GitHub commit in your repo.

4.2 Manually Implementing Changes

4.2.1 Android

Manually add the google-services.json file inside your android/app folder. Commit and push your changes to master branch.

4.2.2 iOS

In order for your generated template to work with push notifications, you will need XCODE installed in your machine.

  1. Open the app/ios/yourProjectName.xcworkspace in Xcode.
  2. Right Click in the left pane and select Add files to … and drop the GoogleServices-Info.plist file into the root iOS directory:

AddFilesToXcode

  1. Select GoogleService-Info.plist and make sure Copy items if needed is selected.
  2. Select the Create Groups option, then select all targets:

GoogleServicesInfoPlist

In Signing & Capabilities tab, add push notifications capabilities to your app by doing the following:

  1. Click nativeTemplate in the left-side file explorer.
  2. Click the Signing & Capabilities tab.
  3. Click Targets > nativeTemplate.
  4. Click Capability, type push in the dialog box, then select Push Notifications.
  5. Click Capability, type background in the dialog box, then select Background Modes.
  6. Select Background Modes > Remote Notifications:

Capabilities

Commit and push your changes to your master branch.

4.3 Customizing the Android Manifest File

Set app launch mode inside activity props and add necessary receiver changes in android/app/src/main/AndroidManifest.xml:

<activity
...
android:launchMode="singleTop"
  >
<application ...>
 <receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver"/>
 <receiver android:enabled="true" android:exported="true"  android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED"/>
    <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
    <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
 </receiver>
 <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
  <intent-filter>
   <action android:name="com.google.firebase.MESSAGING_EVENT" />
  </intent-filter>
 </service>
</application>

AndroidManifestChanges

Congratulations, you finished setting up customizations for your custom native mobile app! To implement remote push notifications on a test device, see How to Use Remote Notifications.

5 Read More