169
Views
8
Comments
Solved
[Firebase] Use Firebase push notification deeplink when application is running on background
Question
firebase
Reactive icon
Forge asset by Labs
Application Type
Mobile

Hello,

I am using Firebase to send push notifications to users. Push notifications are received as expected. However, deeplinks are not always working. I have 2 scenarios

1. The app is not running (when closing the app, you also kill the app in the multitask screen). The pushnotification is received and when you click, the deeplinks work as expected.

2. The app is running in the background (close the app but do not kill the app in multitask screen). The push notification is received, but when you click, the deeplink is not working. 

We figured out what causes this problem. It lays in the action that handles the push notification. This action is placed in the layout (and layoutblank) webblock. This works when opening the app in scenario 1, because the layout webblock is rendered again. However when in scenario 2, the webblock is not refreshed en thus this notification handler is not notified. I know this because I made a logmessage in that FirebaseCloudMessaging action. I tried to use the onParametersChanged to force the webblock to refresh, but this doesn't work. The OnParametersChanged action is called, but the webblock is not actually refreshed. 

Does anyone have a solution for this problem? We would like to force refresh the webblock to let the action know there is a notification to handle. The other solution is changing the javascript of the notification, but we cannot find the javascript that ensures that the application is opened. Any tips on changing the notification behavior are also welcome.


Thanks in advance,

Tyler

2019-09-09 12-23-19
Tyler Cools
Solution

I found the problem! Weirdly, we had some screens where it was working and some screens where it wasn't. That was weird because we used the same layout webblock on both screens. We did some tests and this tests has pointed us to the problem. We had a screen where it was working, we made a new button on a screen which linked to that screen where it was working. The push notification was working when we went to the screen through the working button, but when using the newly made button, the push notifications, again, didn't work. So the journey from button to screen was leading to working or non working push notifications. That is when we decided to change the Module Transition of the button to None (it was previously on slide from left). Now it works!! So appearently the module transition between screens has impact on the push notifications. When changing all module transitions to none, we suddenly had no issues with the push notifications. I will inform OutSystems of this weird behavior

2018-10-29 08-31-03
João Marques
 
MVP

Hi Tyler,


You can also have your app to run the synchronization when resuming the app and pick up data which has not been processed yet (among which the missing notification).

On another project that's what we did, we saved the timestamp the user last synchronized and when the user resumed the app, the synchronization would run picking the information from that point on (including the information behind the push notification).

This would also solve you the situation of having multiple push notifications. When you click on one, you probably want to get the information from all the others (e.g. on WhatsApp if you have 5 unread messages, when you clicking on one notification, they all are erased and the 5 are processed since you see them on the phone).


Hope it helps.


Regards,
João

2019-09-09 12-23-19
Tyler Cools

Hi João,

Thanks for the quick reply. However, I think this will not work for our application. Like you described with WhatsApp, we can have push notifications from different people. When you click on one notification, we need to know to which person the app needs to go. In other words, the screen that needs to be loaded, depends on the information that is stored. When we use the method you describe, I think it is not possible to achieve this. Am I correct?

2018-10-29 08-31-03
João Marques
 
MVP

Hi Tyler,


When we used it, the synchronization would process all the data (so all the 5 messages in my example, pushing them to local storage) but the user would navigate to the deeplink associated to the push notification he clicked. At least on our case, the behavior would be navigating to the screen as defined on the deeplink.


So in my example, if one would receive message from user A and user B, on clicking the notification from user B, then the screen presented would be the conversation with user B but both messages would be pushed to the local storage (this of course depends on the synchronization logic).

2019-09-09 12-23-19
Tyler Cools


This is the part where it goes wrong in our application "but the user would navigate to the deeplink associated to the push notification he clicked.". When we have the app open in the background, our application does not recognize the notification Data and hence also not the deeplink. In other words, when the application is running in the background, the FirebaseCloudMessaging Block is not triggered and thus the notification data cannot be loaded and we cannot access the deeplink data.  The deeplink works correctly when the app is not open in the background but fully killed. Then the layout block is refreshed and the FirebaseCloudMessaging block is triggered.  The data is available then and the deeplink works as expected

2018-10-29 08-31-03
João Marques
 
MVP

The deeplink is nothing more than the URL to the target screen that goes on the push notification so it doesn't need to be processed by the block, just like the message title and body and icon.

So unless, you have a type of rerouting mechanism on the handler block, I'd say it should work if your deeplink contains the correct screen name and eventual parameters. Just like when you write the URL for the given screen on a browser, the user is directed to that given screen (provided he has logged in if the page requires a registered user of course).

2019-09-09 12-23-19
Tyler Cools

I don't fully agree with you on this one. In the 2 scenarios described above, in both scenarios, the app opens when you tap the notification. The difference between the 2 scenarios is that when the app is killed, the app opens and also the deeplink is detected. In scenario 2, the app opens, but the deeplink is not detected. Both scenarios are the exact same push notification, but in scenario 2, the deeplink is not detected. The detection of the deeplink happens in the layout block and the FirebaseCloudMessaging action. and because this block is not refreshed in scenario 2, the deeplink is not detected.

It could be that I'm wrong, so please say so if I am, but I am currently out of options to get this deeplink to work 

2019-09-09 12-23-19
Tyler Cools
Solution

I found the problem! Weirdly, we had some screens where it was working and some screens where it wasn't. That was weird because we used the same layout webblock on both screens. We did some tests and this tests has pointed us to the problem. We had a screen where it was working, we made a new button on a screen which linked to that screen where it was working. The push notification was working when we went to the screen through the working button, but when using the newly made button, the push notifications, again, didn't work. So the journey from button to screen was leading to working or non working push notifications. That is when we decided to change the Module Transition of the button to None (it was previously on slide from left). Now it works!! So appearently the module transition between screens has impact on the push notifications. When changing all module transitions to none, we suddenly had no issues with the push notifications. I will inform OutSystems of this weird behavior

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.