invertase / notifee

⚛️ A feature rich notifications library for React Native.
https://notifee.app
Apache License 2.0
1.81k stars 213 forks source link

[iOS] onBackgroundEvent EventType Press, Dismissed or Delivered doesn't work #1076

Open shonie2xx opened 1 month ago

shonie2xx commented 1 month ago

The onBackgroundEvent works on Android, but not on iOS. The only event type that works for iOS is 7 (TRIGGER_NOTIFICATION_CREATED). Here is how I've implemented it:

const scheduleNotification = async (notificationTimestamp: number) => {
  // Request permissions (required for iOS)
  await notifee.requestPermission();

  // Android 12 limitations
  if (Platform.OS === 'android' && Platform.Version <= 12) {
    const settings = await notifee.getNotificationSettings();
    if (settings.android.alarm !== AndroidNotificationSetting.ENABLED) {
      await notifee.openAlarmPermissionSettings();
    }
  }

  // Create a channel (required for Android)
  const channelId = await notifee.createChannel({
    id: 'reminderId',
    name: 'Reminder',
    vibration: true,
    visibility: AndroidVisibility.PUBLIC,
    importance: AndroidImportance.HIGH,
  });

  // Create a time-based trigger
  const trigger: TimestampTrigger = {
    type: TriggerType.TIMESTAMP,
    timestamp: notificationTimestamp,
  };

  try {
    // Create a trigger notification
    await notifee.createTriggerNotification(
      {
        title: 'Title',
        body: 'Body!',
        android: {
          channelId,
          pressAction: {
            id: 'default',
          },
        },
      },
      trigger,
    );
  } catch (error) {
   recordError(error)
  }
};

In App.tsx I'm expecting the user action this way:

notifee.onBackgroundEvent(async ({ type, detail }) => {

  if (type === EventType.PRESS) {
    console.log('pressed');
  }
  if (type === EventType.DISMISSED) {
    console.log('dismissed');
  }
  if (type === EventType.DELIVERED) {
    console.log('delivered');
  }
});

Please help!

shonie2xx commented 1 month ago

On [Android], the "press" event type also does not trigger when the phone is locked.

stephanie-bassey commented 1 month ago

also experiencing a similar issue

MehmoodArib commented 1 week ago

Any solution here?

Eclipses-Saros commented 4 days ago

check https://github.com/invertase/notifee/issues/616#issuecomment-1380261291. looks like onBackgroundEvent is not like what we think about. use onForegroundEvent.

On [Android], the "press" event type also does not trigger when the phone is locked.

check https://github.com/invertase/notifee/issues/621#issuecomment-2342711032. It's mostly like reactContext is null.