-
Notifications
You must be signed in to change notification settings - Fork 273
Open
Labels
Keep Openthis label avoids the stale botthis label avoids the stale bot
Description
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!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Keep Openthis label avoids the stale botthis label avoids the stale bot