1724
Views
21
Comments
[Firebase Mobile] Push notification configuration guide
Question
Forge component by David Sousa
22
Published on 26 May 2020

In order to configure push notifications, follow the next steps:


1. Firebase configurations

To send push notifications with the Firebase's API you'll need to send a token in the request header. In order to obtain this token, access the Firebase project's console and open the Cloud Messaging settings:

  1. Head to your Firebase project's console.
  2. Click on the side menu's cogwheel, then select Project Settings.
  3. Click on the Cloud Messaging tab.
  4. Save the token correspondent to the Server key found under Project credentials


To send notifications to iOS devices you'll need to connect our app with Apple Push Notification service (APNs) by uploading either the APNs authentication key or APNs certificates. The configuration with APNs authentication key is recommended since it's the most current method for sending notifications in iOS. You can upload these files in the Cloud Messaging settings:

  1. Go to the Cloud Messaging tab in the Project Settings menu.
  2. Upload the authentication key or certificates under iOS app configuration.


2. OutSystems setup - mobile app

In your mobile app you'll need to run the plugin action InitCloudMessaging in:

  • the ApplicationReady system event (if there's already a user logged in) and


  • after the Login action.

It's also needed to run the action UnregisterDevice after logging out.


If you want to handle the push notifications while your users have their app open (in the foreground) you'll have to drag the FirebaseCloudMessaging web block to the required screens. We usually choose to put it in a Layout web block since that way we guarantee it'll be present in all screens.


3. OutSystems setup - server side

In your back-end you'll be using the action SendNotificationToUser, which requires the following inputs:

  1. FCMServerKey - the token you obtained from the Firebase Console in the first steps of this guide
  2. ApplicationId - recommended to use the value obtainable from the OutSystems action GetEntryEspaceName since that's the value used to register the devices when running the action InitCloudMessaging
  3. UserId - the user identifier of the user that'll receive the push notification
  4. Title - the title of the notification
  5. Body - the body of the notification


Remember that you can also test push notifications by using the Firebase Console or external tools, such as Postman, to call the API directly. Here is a link to a Postman collection that already has a template for sending push notifications for Android and iOS.

David,

Thanks for the guide. How does one go about customizing the notification icons to be different from the launcher icons when using this app?

--
Grayson

Rank: #2546

May I know where to find the SendNotificationToUser server action? Which plugin? Thanks

Rank: #1782

Why would you unregister the device on logout?  Would that not stop the device from receiving push notifications?


Jason,

That could be a valid business reason. If a user logs out of any of my business apps that I, as business data owner, don't want them to receive push messages with potential confidential information. For a B2C app without logon (like a project app to inform your stakeholders/neighborhood) you could choose to only register the device since the message will then be public by definition.

Hello David, i've sent you a message but i guess you didn't notice so i just post the question here.


I am new to Outsystems, currently developing a mobile app for client's internal employee. According to the guides from the Firebase forge component, the UserId (the user identifier of the user that'll receive the push notification) only can be used if the identifier obtained from Outsystems Users DB. What if I create a new entity that contains employees information and use the Identifier from that entity as a parameter Firebase push notification? Is it possible? Or it only works for Outsystems Users DB?


Thanks before.

Rank: #79290

David Sousa wrote:

In order to configure push notifications, follow the next steps:


1. Firebase configurations

To send push notifications with the Firebase's API you'll need to send a token in the request header. In order to obtain this token, access the Firebase project's console and open the Cloud Messaging settings:

  1. Head to your Firebase project's console.
  2. Click on the side menu's cogwheel, then select Project Settings.
  3. Click on the Cloud Messaging tab.
  4. Save the token correspondent to the Server key found under Project credentials


To send notifications to iOS devices you'll need to connect our app with Apple Push Notification service (APNs) by uploading either the APNs authentication key or APNs certificates. The configuration with APNs authentication key is recommended since it's the most current method for sending notifications in iOS. You can upload these files in the Cloud Messaging settings:

  1. Go to the Cloud Messaging tab in the Project Settings menu.
  2. Upload the authentication key or certificates under iOS app configuration.


2. OutSystems setup - mobile app

In your mobile app you'll need to run the plugin action InitCloudMessaging in:

  • the ApplicationReady system event (if there's already a user logged in) and


  • after the Login action.

It's also needed to run the action UnregisterDevice after logging out.


If you want to handle the push notifications while your users have their app open (in the foreground) you'll have to drag the FirebaseCloudMessaging web block to the required screens. We usually choose to put it in a Layout web block since that way we guarantee it'll be present in all screens.


3. OutSystems setup - server side

In your back-end you'll be using the action SendNotificationToUser, which requires the following inputs:

  1. FCMServerKey - the token you obtained from the Firebase Console in the first steps of this guide
  2. ApplicationId - recommended to use the value obtainable from the OutSystems action GetEntryEspaceName since that's the value used to register the devices when running the action InitCloudMessaging
  3. UserId - the user identifier of the user that'll receive the push notification
  4. Title - the title of the notification
  5. Body - the body of the notification


Remember that you can also test push notifications by using the Firebase Console or external tools, such as Postman, to call the API directly. Here is a link to a Postman collection that already has a template for sending push notifications for Android and iOS.



Rank: #19048

David Sousa 

I'm working on iOS and Android push notification. On Android, able to receive notification. Where as on iOS not able to receive.

I cross checked the certificates, generating app on React-Native with same firebase environment. There seems no issue with certificates. 

Can you please, let me know, what could be any other reason that would cause the issue. It has been more than 2 weeks, stuck with this issue. No way to move forward.

Rank: #139

Hi all,

I've just tested sending a notification for an iOS device and it works (using plugin version 1.0.7).

I'll need some more context in order to help you.

Have you tried sending a push notification by directly calling the Firebase API?

Rank: #139

How are you setting the iOS app configuration on the Firebase console? Using authentication key or certificates?

Can you please try the following:

  1. Generate new p8 file in Apple Developer
  2. Set the p8 file in the Firebase console (with correct key and team ID's)
  3. Set the p8 file and generate a new mobile app build
  4. Install the new mobile app build
  5. Test receiving push notification
Rank: #19048

David Sousa

Can you please explain, why I'm able to receive notification on foreground on iOS?

That can help me to narrow down problem. 

The logic implementation of foreground vs background

Rank: #139

Hi there,

I re-tested the push notifications on a different iOS app and once again it worked as intended. Notifications are delivered independently of the status of the app.

There's no specific logic implementation for foreground or background. The plugin adds the Firebase SDK to the build, which is responsible for handling notifications. My wild guess is that the device isn't registering correctly with APN's because of some wrong configurations and the notification you receive with the app on foreground is actually a data message, which doesn't rely on APN's (check Firebase documentation here).

My advice would be to:

  • review the configuration and check again the setup of certificates / APNs
  • give me some more context (which plugins you have besides Firebase, Firebase API call request/responses, etc)
  • debug your app so that you find the issue by yourself

Cumps,

David

Rank: #3653

Hi David,

Am the colleague of Kalyan , we are getting the following issue:Error installing Cordova plugin: cordova-plugin-firebase.In iOS on 2020-02-13 at 16:53:17 - Error installing Cordova plugin: cordova-plugin-firebase.


Steps we have followed to build the app:

1)Created Firebase application for both ios and android.

2)Uploaded APNS for ios in firebase console.

3)Downloaded plist and googleservices.json and made zip and attached under resources file. and deployed it in the target directory.(with the firebase.appidentifier).

4)We have used Firebase Mobile 1.0.6 version and MABS 5.2 version.(we are using outsystems 11)

5)For build generation we have added developer certificate and provisioning profile.

what else we have missed please let us know help us in solving this issue .


Thanks

Harish


Rank: #139

Harish and Kalyan,

From what I understood from your private messages, the issue with the iOS notifications might be related with the ADAL plugin.

Fortunately there's an easy fix for that. If you search the ADAL plugin forums you'll find this thread with the solution:

https://www.outsystems.com/forums/discussion/53581/ios-azure-ad-firebase-mobile-plugins-incompatibility/

Cumps
David

Rank: #3653

Hey David,

thanks we made the change it is working fine now in ios as well.

Thanks

Harish

Rank: #47899

Hello, Can you tell me about send push notification to spesific user?, i confused about this if you have example project about send push notification to spesific user can you send to this forum?? 

Thank's 

Rank: #5163

is anybody know how to setup firebase for pwa/reactive web in outsystems?