Stefano Giacone Stefano Giacone - 1 year ago 99
iOS Question

Firebase Pull notification

I'm working with Firebase Cloud Messaging. I have a couple of question I was not able to understand from the documentation:

  1. Android: Lets suppose the app is closed (not backgrounded: closed). If I send a notification with also the data payload, this data payload is passed to the activity through the Intent Extra

Messages with both notification and data payload, both background and
In this case, the notification is delivered to the
device’s system tray, and the data payload is delivered in the extras
of the intent of your launcher Activity.

What if the user does not tap on the notification? Is the data payload lost? Is there a way to retrieve it?

  1. iOS/Android. Lets suppose the user disabled the notification and I sent a notification to the client: is there a way to retrieve (pull) the notification at the application start?

Thanks very much

Answer Source

If the app is closed (not in background) the onMessageReceived method is called when the notification is received and there you can retrieve the data payload with remoteMessage.getData().get("key_for_parameter"); where key_for_parameter is the name of the parameter that you send in the notification. This method is called even if the application is closed. However, take into account that the "onMessageReceived" is called only if you omit the "notification" param in the notification (look this post)

So once you have the params in the onMessageReceived you can look for an strategy to use them in your application like storing in the DB and you are not going to lose the data if the user does not click on the notification.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download