Skip to content

onBackgroundEvent not triggered on iOS for remote notifications #1133

@riad40

Description

@riad40

I'm encountering an issue where the onBackgroundEvent handler is not triggered on iOS when a remote notification is received. The same functionality works perfectly fine on Android.

Environment:

Notifee version: ^9.1.2
React Native version:"0.72.5"
Platform: iOS

Relevant Code:

async function initializeNotifications() {
  await notifee.setNotificationCategories([
    {
      id: '// some id',
      actions: [
        { id: 'YES', title: 'YES', foreground: false },
        { id: 'NO', title: 'NO', foreground: false },
        { id: 'CHECK', title: 'CHECK', foreground: true, authenticationRequired: true },
      ],
    },
  ]);
}

async function onMessageReceived(message) {
  console.log('Message received:', message);
  const notificationData = { /* ... */ };
  await notifee.displayNotification({
    ...notificationData,
    android: {
      channelId: '// some channel id',
      actions: [
        { title: 'YES', pressAction: { id: 'YES' } },
        { title: 'NO', pressAction: { id: 'NO' } },
        { title: 'CHECK', pressAction: { id: 'CHECK' } },
      ],
    },
    ios: {
      categoryId: '// some category id',
    },
  });
}

notifee.onBackgroundEvent(async ({ type, detail }) => {
  console.log('Background event received:', type, detail);
  switch (type) {
    case EventType.ACTION_PRESS:
      await handleNotification(detail);
      break;
    case EventType.PRESS:
      // i navigate to certain screen
      break;
  }
});

messaging().setBackgroundMessageHandler(onMessageReceived);
initializeNotifications().catch(console.error);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions