首页 > 解决方案 > 世博会本地通知如何设置每天开始和重复的时间?

问题描述

我很难弄清楚最新版本的世博会如何在一天中的特定时间设置本地通知并使其每天重复。

"expo": "~40.0.0",
"expo-notifications": "~0.8.2",
function startsTomorowButNotAbleToRepeateEvryDay() {
  let tomorrow = new Date();
  tomorrow.setDate(tomorrow.getDate() + 1);
  tomorrow.setHours(20);
  tomorrow.setMinutes(0);

  return {
    content: {
      title: "Time to study v2",
      body: "Don't forget to study today!",
    },
    trigger: tomorrow,
  };
}

function repeatsEvryDayButNotPossibleToSetTime() {
  const seccondsInADay = 24 * 60 * 60;

  return {
    content: {
      title: "Time to study v2",
      body: "Don't forget to study today!",
    },
    trigger: {
      seconds: seccondsInADay,
      repeats: true,
    },
  };
}
Notifications.scheduleNotificationAsync(startsTomorowButNotAbleToRepeateEvryDay());
Notifications.scheduleNotificationAsync(repeatsEvryDayButNotPossibleToSetTime());

如何从明天的特定时间开始通知并每天重复?

标签: react-nativenotificationsexpolocal

解决方案


来自 Notifications.types.d.ts

export interface DailyTriggerInput {
    channelId?: string;
    hour: number;
    minute: number;
    repeats: true;
}

您可以使用:

trigger: {
    hour: 19;
    minute: 45;
    repeats: true;
}

推荐阅读