Skip to content

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

@shonie2xx

Description

@shonie2xx

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Keep Openthis label avoids the stale bot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions