Part 5: Implement Push Notifications in Your Native App
Introduction
This guide will help you set up, build, and publish your native app to handle push notifications. Deploying your iOS or Android app allows the server to send push notifications to mobile devices which have your app installed.
To make setup easy, the Push Notifications Connector module includes snippets that will help you with the initial setup. Do the following:
- Expand the Marketplace modules > PushNotifications > USE ME folder.
- Find and copy the Native folder.
- Paste the Native folder contents into your own app’s navigation.
- In your app’s navigation, expand the new Native folder.
- Copy the NativeHomepage_Snippet snippet.
- Paste the snippet into your Native navigation’s home page.
App Events Widget
Completing the previous section brings the App events widget into your app. This widget is already configured and part of a snippet, so you should not need to change it.
If you already had an App events widget on your home page, follow these steps:
- Open the App events widget.
- In Page load, select Call a nanoflow from the On load drop-down list.
- For Nanoflow, click Select and specify the nanoflow OnPageLoad_RegisterPushNotifications from the PushNotifications module:
- If you already have a nanoflow selected, make a Call nanoflow activity to the nanoflow in that existing nanoflow.
- If you already have a nanoflow selected, make a Call nanoflow activity to the nanoflow in that existing nanoflow.
- In App resume, select Call a nanoflow from the On Resume drop-down list.
- For Nanoflow, click and specify the nanoflow OnPageLoad_RegisterPushNotifications from the PushNotifications module:
- If you already have a nanoflow selected, make a Call nanoflow activity to the nanoflow in that existing nanoflow.
- If you already have a nanoflow selected, make a Call nanoflow activity to the nanoflow in that existing nanoflow.
Notifications Widget
The snippet also adds the Notifications widget which lets users interact with the notifications the app receives.
By default this widget is configured with an Example action. It uses a non-persistable entity (NPE) that stores data received from the notifications. It then uses that data in the nanoflow upon receiving or opening the notification. Use this example to make your own actions.
Customizing Offline Synchronization
To ensure push notification integration executes properly on your native app you must adjust the objects that are synchronized to your mobile device:
- Open your app’s Navigation.
- Click the Native mobile (tablet & phone) navigation tab.
- Click the Synchronization configuration button.
- If it is not already added, add the DeviceRegistration entity from the PushNotifications module.
- From the Download dropdown menu, select All Objects for that entity and click OK.
This will ensure that the correct objects are synchronized to your native apps.
Building Your Native App
Now that you have everything set up, it is time to deploy your native app:
-
In Studio Pro top bar navigation, click App > Build Native Mobile App:
- If you are building your native app for the first time, click here for instructions.
-
After choosing the type of build (local development or distribution) go to App capabilities.
-
Under Firebase configuration switch Push notifications to On.
-
Scroll down and upload the Firebase configurations:
- google-services.json for the Android build.
- GoogleServices-Info.plist for the iOS build.
These files contain the information and private keys necessary to enable push notifications in your iOS and Android apps.
File Source Usage google-services.json Google Firebase Firebase configuration and private key, bundled as part of your Android application. GoogleServices-Info.plist Google Firebase Firebase configuration and private key, bundled as part of your iOS application. -
Save the configuration. Now you are ready to build.
When building for local development, keep in mind that Mendix’s Make It Native app does not support push notifications. In order to use and test push notifications, you will have to build your own native app as described above and distribute it to an emulator (Android only) or test device.
Now you are able to build, the next step is to run your app in an emulator or test device. Proceed to part 7 to send your first push notifications or continue with the next section to set up push notifications for progressive web apps.