iOS post data in background after user selects notification action

Viewed 40

I am working on an Expo (React-Native) app and am trying to figure out if I am hitting a limitation of Expo or iOS. I am sending a push notification with actions and trying to receive the user's chosen action and upload it to a server, all while keeping the app in the background. Currently, I am able to receive the user's action in the background but my post doesn't execute until I foreground the app again.

I have looked through the iOS documentation regarding handling push notification actions and haven't seen anything about limitations besides file-system access for when the device is locked. Would this require an background-fetch or remote-notifications? Neither really apply because this is a user activated action rather than some automatic fetch or silent notification.

I setup a Glitch & a Snack to demonstrate this issue. https://snack.expo.dev/@thefinnomenon/14004

https://glitch.com/edit/#!/destiny-abundant-cord?path=README.md%3A1%3A0

1 Answers

I am currently experiencing the same behavior. You can force the app into the foreground when the action is selected by specifying UNNotificationActionOptionForeground when registering the UNNotificationAction, but I have not found a way to handle the notification action in the background with server communication.

Did you find a better solution to this?

UPDATE: I discovered a better solution myself. The following conditions must be met in order for this to work.

  1. The completion handler must always be called.
  2. The completion handler must be called after the result has been received from the server.
  3. The completion handler must only be called on the main thread.
Related