How to handle push notifications for app in foreground?(Firebase)

From what I have read, in firebase, when a push notification is sent and the user has the app open (in foreground) the “data” portion of the push notification is send to/ handled by the client app. (app made using AppGyver) Is there a way we can use this data or is that not possible with AppGyver?

Hi @Donnico_Miller

I’m new in the AppGyver world but I’m trying to master the Firebase inside the AppGyver.

I didn’t play with push notification yet, but on the “logic for GLOBAL CANVAS”, you have a set of event types that you can select. There is one called ‘Notification Received’ and I would try this one.

Please, if you figure out how to handle push notification with the app in foreground put all the detail in this thread :slight_smile:

Thank you, I will check it out

When I try this it gives out an empty value “{ }” for the receive event, and for the event.value it gives me “undefined”

I have decided to exclude this in my app for now, but will go back to it in the near future

If your push notification is an object from firebase database, which is what I do, all you have to do is use in notification received event and make a container visible containing the latest object in firebase which triggers the notification. I have done it and it works well in global canvas.

I don’t completely understand, may you send a screenshot please

Yeah I will when I get home. I’m on my cell right now. Until then, what is the notification being sent for?

The notification is to alert users for deadlines of the things they posted on the app. I have the notifications working already (with firebase too)

Ok. What I do, is I write the notification data to a collection in firebase, and retrieve in a page for users to view all notifications in the app, kind of like messages, the same way Facebook does it, ordered by date and triggered by various events. Then, the push notif itself is triggered by a new document added to the notifications collection. So I know, if a user is in the app and received a notification, the data fir the notuf is the last object added to the collection for which the field user id matches the current user, so, in the on notif received event, I simply get the last documents with a get record request, or a get record collection request and dually the very first item in a in app container using a fade in animation. In the click event, I send the user to their notification page, where they can see all nitufs, just like Facebook does. When the user clicks one if the notufs, the event varies based in the field notifType

Sorry, but I still don’t completely understand. The notification data in from my push notifications only contain text as the subject and message, but I don’t know how to access that text from the notification received event, when a notification is sent. I just get this: {}

( For anybody looking at this later)


The “receive event” output only gives an empty object and the “.eventvalue” gives nothing. The “.event” output gives the full data object and its what you want to select. However in order to show the notification it to the users ( I use a toast) you wouldn’t want them to see the full object just the message so I extratcted the message (or title or both) from the object using the LOOKUP formula. You can replace “body” with title for the title and join them together with “+” and maybe “\n” to skip a line.

** This is for push notifications with firebase (CURL example from AppGyver docs:

Thanks to @Daniel_Perley1 for the help and @Kleyson_Rios this is the details if you still want to implement it.

1 Like