airship-flutter icon indicating copy to clipboard operation
airship-flutter copied to clipboard

notificationId in PushPayload is null for iOS

Open AnastasiiaSob opened this issue 1 year ago • 5 comments

Preliminary Info

What Airship dependencies are you using?

airship_flutter: ^7.7.1

What are the versions of any relevant development tools you are using?

Flutter 3.22.3

Report

What unexpected behavior are you seeing?

After sending a push notification from Airship to my physical iOS device and calling Airship.push.onPushReceived.listen((event) {...} I get a PushPayload Object that contains the property notificationId with a null value. I can see the push notification on my screen and I see the payload in my console. For example: PushPayload( notificationId=null, alert=TEXT from Airship, title=title from airship, subtitle=null, extras={ com.urbanairship.metadata: eyJ2ZXJ...., com.urbanairship.media_attachment: {url: [......] }, ^u: https://www.google.com})

What is the expected behavior?

After sending a push notification from Airship to my physical iOS device and calling Airship.push.onPushReceived.listen((event) {...} I assume to get a PushPayload Object that contains a not-null property notificationId.

What are the steps to reproduce the unexpected behavior?

Send a push notification to an iOS device while the app is in foreground and active. Access the PushPayload Object event.pushPayload in the onPushReceived listener. The push notification is not a silent push.

Do you have logging for the issue?

In the info above.

AnastasiiaSob avatar Sep 02 '24 10:09 AnastasiiaSob

If you are trying to get the notification ID from a content-available push in the background, Apple does not deliver that id with the callback that we are given to listen for that event. There is a limitation on the Airship SDK where we are dropping the ID if the push is received in the foreground in the callback that we need to expose it to flutter. We can look into addressing that but it will take some time.

rlepinski avatar Sep 03 '24 16:09 rlepinski

@rlepinski yes, the is no notificationId with a content-available push in the background as well as in the foreground. That would be of great value, as our feature implementation depends on the uniqueness check for push notifications based on the notificationId. For Android, there is a field 'com.urbanairship.push.CANONICAL_PUSH_ID' to access the notificationId ID. Is there a workaround for now? Or could you estimate how long it would take to address this issue?

AnastasiiaSob avatar Sep 03 '24 19:09 AnastasiiaSob

We wont be able to provide you the notification ID in the background for content-available push, only when the device is in the foreground.

A workaround would be to set your own unique ID, then use the getNotifications method and look for that ID in the extras.

rlepinski avatar Sep 04 '24 15:09 rlepinski

@AnastasiiaSob I don't think we can solve your issue with just adding the foreground ID, that would catch some of it but the majority of the time notifications will be received in the BG. I think instead you should use this solution - https://github.com/urbanairship/airship-flutter/issues/200#issuecomment-2274435829

Then use onPushReceived, onForeground events to pull your data from that store. That would be the most reliable way of getting the list of notifications

rlepinski avatar Sep 11 '24 15:09 rlepinski

@rlepinski thank you for your suggestion! We found out that in onPushReceived the notifications do have notificationId's if they are accessed through await Airship.push.activeNotifications. We took it as a workaround for now.

AnastasiiaSob avatar Sep 11 '24 15:09 AnastasiiaSob