1import { UnavailabilityError } from 'expo-modules-core';
2
3import NotificationScheduler from './NotificationScheduler';
4
5/**
6 * Cancels a single scheduled notification. The scheduled notification of given ID will not trigger.
7 * @param identifier The notification identifier with which `scheduleNotificationAsync` method resolved when the notification has been scheduled.
8 * @return A Promise resolves once the scheduled notification is successfully canceled or if there is no scheduled notification for a given identifier.
9 * @example Schedule and then cancel the notification:
10 * ```ts
11 * import * as Notifications from 'expo-notifications';
12 *
13 * async function scheduleAndCancel() {
14 *   const identifier = await Notifications.scheduleNotificationAsync({
15 *     content: {
16 *       title: 'Hey!',
17 *     },
18 *     trigger: { seconds: 60, repeats: true },
19 *   });
20 *   await Notifications.cancelScheduledNotificationAsync(identifier);
21 * }
22 * ```
23 * @header schedule
24 */
25export default async function cancelScheduledNotificationAsync(identifier: string): Promise<void> {
26  if (!NotificationScheduler.cancelScheduledNotificationAsync) {
27    throw new UnavailabilityError('Notifications', 'cancelScheduledNotificationAsync');
28  }
29
30  return await NotificationScheduler.cancelScheduledNotificationAsync(identifier);
31}
32