1import { UnavailabilityError } from 'expo-modules-core';
2import { v4 as uuidv4 } from 'uuid';
3
4import NotificationPresenter from './NotificationPresenterModule';
5import { NotificationContentInput } from './Notifications.types';
6
7let warningMessageShown = false;
8
9/**
10 * Schedules a notification for immediate trigger.
11 * @param content An object representing the notification content.
12 * @param identifier
13 * @return It returns a Promise resolving with the notification's identifier once the notification is successfully scheduled for immediate display.
14 * @header schedule
15 * @deprecated This method has been deprecated in favor of using an explicit `NotificationHandler` and the [`scheduleNotificationAsync`](#notificationsschedulenotificationasyncrequest) method. More information can be found in our [FYI document](https://expo.fyi/presenting-notifications-deprecated).
16 */
17export default async function presentNotificationAsync(
18  content: NotificationContentInput,
19  identifier: string = uuidv4()
20): Promise<string> {
21  if (__DEV__ && !warningMessageShown) {
22    console.warn(
23      '`presentNotificationAsync` has been deprecated in favor of using `scheduleNotificationAsync` + an explicit notification handler. Read more at https://expo.fyi/presenting-notifications-deprecated.'
24    );
25    warningMessageShown = true;
26  }
27
28  if (!NotificationPresenter.presentNotificationAsync) {
29    throw new UnavailabilityError('Notifications', 'presentNotificationAsync');
30  }
31
32  return await NotificationPresenter.presentNotificationAsync(identifier, content);
33}
34