pushy / pushy-flutter

The official Pushy SDK for Flutter apps.
Apache License 2.0
21 stars 19 forks source link

Can't save to local storage of notification received on ios when app is closed #46

Closed cabonitavince closed 2 years ago

cabonitavince commented 2 years ago

backgroundNotificationListener method always calls every time new notification received, Also I call my save notification function inside it. When app is foreground and in the background it works fine, the notification saved to the local storage but if app is closed it is not working. This works fine on android.

pushy commented 2 years ago

Hi @cabonitavince, We'd be glad to assist.

  1. On Android, the backgroundNotificationListener is indeed supposed to be getting invoked on every incoming notification, even in foreground, so your app can process it accordingly. This is expected behavior.

  2. If you'd like the backgroundNotificationListener to be invoked on iOS while your app is in the background (not killed/swiped away), consider sending silent notifications to your iOS users.

Simply pass the content_available: true parameter in the Send Notifications API request body and omit the notification object to send a silent notification:

{
    "to": "a6345d0278adc55d3474f5",
    "data": {
        "silentPayloadData": "Hello World"
    },
    "content_available": true
}

Note: Silent notifications require the Background Modes -> Remote Notifications capability to be enabled in the Xcode project settings.

Additional Note: Due to Apple platform restrictions, silent notifications will not be delivered to your app if it has been swiped away from the recent apps / killed. If you'd like notifications to be received in this scenario, please consider sending regular (non-silent) iOS notifications, without the content_available: true flag. However, you won't be able to execute code - the notifications will simply be displayed to the user when your app is closed.

Furthermore, Apple restricts the number of silent notifications you can send to a device in a given day to about 5. Sending too many to the same device in a single day, or sending them in quick succession, will lead to those notifications being throttled (and dropped) by APNs.

Please let us know if there's anything else we can help with.

cabonitavince commented 2 years ago

I mean I can't execute code inside backgroundNotificationListener when app is closed on ios. Is there a way on how to execute code inside backgroundNotificationListener when app is closed on ios? Because everything works fine in android.

pushy commented 2 years ago

Hi @cabonitavince,

Due to Apple platform restrictions, silent notifications will not be delivered to your app if it has been swiped away from the recent apps / killed. There is no way around this. Apps on iOS cannot execute code silently when killed.

If you'd like notifications to be received in this scenario, please consider sending regular (non-silent) iOS notifications, without the content_available: true flag. However, you won't be able to execute code - the notifications will simply be displayed to the user when your app is closed.

cabonitavince commented 2 years ago

Ok noted on this. Thanks for the help!