Notifications listeners acting differently than documented

Hi I’m trying to make sure my app handles foreground and background notifications correctly but my testing is conflicting
with the table here

my testing through testflight on my iphone shows the following:
*** where ‘fg handlers’ are the notification listeners and ‘bg handler’ is the notifications background task***

background + no interaction: nothing
background + touched: fg handlers
background + fg/bg interaction: fg handlers
killed + background interaction: fg handlers (but only the next time the app is started)
killed + foreground interaction: fg handlers
killed + touched: bg handler + fg handlers
killed + no interaction: nothing

these conflict with the table in the docs in that the background task is never called when the app is in the background but is called when
the app is killed and then a notification is touched (opening the app). Also, for interactive actions that don’t bring the app into the foreground from being killed,
their code seems to only be run the next time the app is open. Is there a way to make it run when the user does the interaction?

In terms of my internal design around notifications, I have a NotificationStore that gets injected into components that need to respond to notifications/their interactions and is bound to an identifier before the app is started up.



When the app does start, a hook sets up the listeners for the foreground notifications and returns the destructor to tear it down.

container.bind(INotificationStore.id).to(NotificationStore);
// ...
export default function App() {
  useEffect(() => {
      const notificationStore = getStore<INotificationStore>(INotificationStore);
      notificationStore.setup();

      return () => {
        notificationStore.teardown();
      }
    })
  //...
}

in the NotificationStore file, I also define/register the background task and interactive notification definitions so when the NotificationStore is bound to its DI identifier before app start, the registrations will happen.

TaskManager.defineTask(INotificationStore.BACKGROUND_NOTIFICATION_TASK, async ({ data, error, executionInfo }) => {
    console.log('Received a notification in the background!');

    if (data) {
        if (Device.brand == "Apple") {
            const notification = data['UIApplicationLaunchOptionsRemoteNotificationKey'].body as NotificationPayload<any> & { type : NotificationType };
            await API.logNotification(notification)
            Alert.alert('finished api call')
        } else if (Device.brand == "Google") {
            // ...
        }
    } else if (error) {
        // ...
    }
});

Notifications.registerTaskAsync(INotificationStore.BACKGROUND_NOTIFICATION_TASK);

(async function() {
    try {
        // static method
        await NotificationStore.registerInteractiveNotifications()
        console.log('categories initialized')
    } catch (e) {
        console.error(e);
    }
})()

Are the docs wrong? Am I doing something wrong? Or is it both? :slight_smile:

bump!