invertase / react-native-notifee

Moved to https://github.com/invertase/notifee
https://invertase.io/blog/open-sourcing-notifee
Other
466 stars 31 forks source link

Timestamp Notification seems not work on Real device #343

Closed nhatndm111993 closed 3 years ago

nhatndm111993 commented 3 years ago
setScheduleNotification: async (payload) => {
    try {
      const { time, title, body } = JSON.parse(payload);
      let channelId;
      let notifcationObj;

      if (Platform.OS === "android") {
        channelId = await notifee.createChannel({
          id: "schedule_notification",
          name: "Schedule Notification Channel",
        });

        notifcationObj = {
          android: {
            channelId,
          },
        };
      }

      const trigger = {
        type: TriggerType.TIMESTAMP,
        timestamp: time,
      };

      if (title) {
        notifcationObj = {
          ...notifcationObj,
          title,
        };
      }

      if (body) {
        notifcationObj = {
          ...notifcationObj,
          body,
        };
      }

      await notifee.createTriggerNotification(
        notifcationObj,
        trigger,
      );
    } catch (e) {
      Sentry.captureException(e);
    }
  },