Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

[iOS] onBackgroundEvent is not triggered on large apps with complex startup tasks #597

@bohomi

Description

@bohomi

Hi Notifee team, I'm very excited to use this library for both local and remote notifications however my question is focused on local notifications for iOS only.

I'm trying to setup notifications quick actions, for example postponing the notification for an hour or liking a piece of content.
Through testing I noticed that the notifee.onBackgroundEvent is not called when the app is force killed unless my app is very basic. In a 'real-world' large app, the onBackgroundEvent is not called unless the app is manually re-opened by the user or the quick action is pressed a few times on different notifications.

My thinking is that the App component is registered and the whole js bundle is loaded when the notifee.onBackgroundEvent is triggered, hence why the example works on small apps but not large ones.

In your experience, what would be the correct setup for notifee.onBackgroundEvent so that the whole app js bundle is not loaded causing the OS to not deliver the notification as intended? Thank you 😄

Please let me know if you need additional details or clarifications. In the example imagine AppStack as a large, nested navigator with a lot of UI loaded components and useSomeExpensiveSetup as a bunch of hooks that setup other app functions like audio library, analytics, monitoring software etc.
Below is my setup.

testing on real device iPhone 8
libraries:

"react": "17.0.2",
"react-native": "0.67.5",
"@notifee/react-native": "^7.1.0",

my index.js:

/**
 * @format
 */
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

import notifee, {EventType, TriggerType} from '@notifee/react-native';

// Notifee
notifee.onBackgroundEvent(async ({type, detail}) => {
  const {notification, pressAction} = detail;

  // Check if the user pressed the "Postpone action" action
  if (
    type === EventType.ACTION_PRESS &&
    pressAction.id === 'TEST_REMINDER_POSTPONE_IMMEDIATE' // postpone notification by 1min
  ) {
    const now = new Date();
    const trigger = {
      type: TriggerType.TIMESTAMP,
      timestamp: now.getTime() + 60 * 1000, // 60s delay
    };

    const postonedNotification = {
      title: 'A postponed notification',
      body: 'Postponed by 1min',
      ios: {
        categoryId: 'TEST_CATEGORY',
      },
    };

    console.log('postponed notification');
    await notifee.createTriggerNotification(postonedNotification, trigger);

    // Remove the notification
    await notifee.cancelNotification(notification.id);
  }
});

AppRegistry.registerComponent(appName, () => App);

my App.js:

const App: () => React$Node = () => {
  useNotifeeSubscribeToForegroundEvents();

  useSomeExpensiveSetup(); // this may take longer to setup like purchasing libraries, audio libraries, analytics etc

  return (
    <Provider store={store}>
      <PersistGate loading={null} persistor={persistor}>
        <AppStack  />  // AppStack loads a large app
      </PersistGate>
    </Provider>
  );
};

export default App;

iOS background modes

Screenshot 2022-11-24 at 16 11 22
Screenshot 2022-11-24 at 16 11 13

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions