Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onBackgroundEvent not triggered on iOS for remote notifications #1133

Open
riad40 opened this issue Oct 26, 2024 · 1 comment
Open

onBackgroundEvent not triggered on iOS for remote notifications #1133

riad40 opened this issue Oct 26, 2024 · 1 comment

Comments

@riad40
Copy link

riad40 commented Oct 26, 2024

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);
@LunatiqueCoder
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants