static init()

in src/components/push-notifications/push-notifications-processor.ts [70:124]


  static init() {
    let resolveToken: TokenHandler = (token) => {};

    let rejectToken: TokenHandler = (reason) => {};

    this.deviceTokenPromise = new Promise<string>(
      (resolve: TokenHandler, reject: TokenHandler) => {
        resolveToken = resolve;
        rejectToken = reject;
      },
    );
    Notifications.registerRemoteNotifications();
    Notifications.getInitialNotification()
      .then(notification => {
        if (notification) {
          log.info(`Push notifications processor: Initial notification detected`);
        }
      })
      .catch(err => log.info(`Push notifications processor: Initial notification detection failed ${err}`));
    Notifications.events().registerRemoteNotificationsRegistered(
      (event: { deviceToken: string }) => {
        this.setDeviceToken(event.deviceToken);
        resolveToken(event.deviceToken);
      },
    );
    Notifications.events().registerRemoteNotificationsRegistrationFailed(
      (error: RegistrationError) => rejectToken(error),
    );
    Notifications.events().registerNotificationReceivedForeground(
      (
        notification: Notification,
        completion: (response: NotificationCompletion) => void,
      ) => {
        log.info(`Push notifications processor: Notification received in foreground`);
        completion({
          alert: true,
          sound: true,
          badge: false,
        });
      },
    );
    Notifications.events().registerNotificationReceivedBackground(
      (
        notification: Notification,
        completion: (response: NotificationCompletion) => void,
      ) => {
        log.info(`Push notifications processor: Notification received in background`);
        completion({
          alert: true,
          sound: true,
          badge: false,
        });
      },
    );
  }