[IOS] Best way to handle received notification when app is closed? #7494
Replies: 1 comment 1 reply
-
🤔 you may find that this business requirement is not possible to fulfill completely. From a user / operating system perspective, what you are saying is: "even though the user has closed the app, perhaps because they are very low on battery and are managing resources really closely to save 2% battery to get an emergency call from their child or because they are roaming on an expensive network, I would like the app to wake up and initialize and keep the cellular or wifi chips enabled so I can run my code and send data to the network so I get a delivery report" From a user perspective, this is sometimes unwanted behavior. Sure sometimes it is wanted but sometimes it is unwanted. From an operating system perspective, this is unwanted frequently enough and abused often enough by apps that the operating system discourages this and makes it both difficult to do, unreliable, and maybe delayed even if it does happen. Especially on iOS. So, carefully consider whether you can meet this requirement or even if you should. That said, the way to do it is to follow the instructions on handling background "data-only" messages maybe - though these will be unreliable - or look into implementing a Notification Helper on iOS that let's you run a little code before notification displays or similar on android (probably a topic for stackoverflow to see how to run code when a notification comes in - I'm not sure myself - I use data-only notifications on android along with setBackgroundMessageHandler there but I accept they may be unreliable) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When I receive a notification, I need to tell the server the notification was delivered.
When the app is in the foreground, everything is pretty straightforward since we just handle it in onMessage method.
When app is closed is another story.
In short, I need to find a way to send a request to the server that tells it user has received the notification, and pass the guid of the message, uid of the device and date of the message. I suppose it should be done through native code.
Any help would be appreciated
Beta Was this translation helpful? Give feedback.
All reactions