128
Views
0
Comments
[Firebase Mobile] Push Notifications whilst user has app open bug ?
Question
Forge component by David Sousa
22
Published on 26 May 2020

Is there a bug in cloudNotification-> FirebaseCloudMessaging -> NotificationHandler ?



The notification JSON feed to the HandleNotificationData javascript is of the format 

{"gcm.message_id":"1575606863892691","tap":false,"google.c.a.e":"1","aps":{"alert":{"title":"Example Message Title","body":"Example Message Body"}}}



But the Javascript is not drilling into 'aps' and 'alert'


if($parameters.NotificationJSON) {
    var notificationData = JSON.parse($parameters.NotificationJSON);
    $parameters.Title = notificationData.title ? notificationData.title : "";
    $parameters.Body = notificationData.body ? notificationData.body : "";

    $parameters.Deeplink = notificationData.click_action ? notificationData.click_action : "";
    $parameters.AppInBackground = notificationData.tap ? notificationData.tap : false;
       
    var data = extractDataFromNotification(notificationData);
    $parameters.DataKeyValues = JSON.stringify(data);
}


 I've made the change below which looks to work now in our app


if($parameters.NotificationJSON) {
    var notificationData = JSON.parse($parameters.NotificationJSON);
    $parameters.Title = notificationData.aps.alert.title ? notificationData.aps.alert.title : "";
    $parameters.Body = notificationData.aps.alert.body ? notificationData.aps.alert.body : "";

    $parameters.Deeplink = notificationData.click_action ? notificationData.click_action : "";
    $parameters.AppInBackground = notificationData.tap ? notificationData.tap : false;
       
    var data = extractDataFromNotification(notificationData);
    $parameters.DataKeyValues = JSON.stringify(data);
}