世博会本地通知如何设置每天开始和重复的时间?

时间:2021-01-09 15:17:52

标签: react-native notifications expo local

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

  • package.json 中的相关部分
"expo": "~40.0.0",
"expo-notifications": "~0.8.2",
  • 我可以使用此 sipet 创建通知
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());

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

1 个答案:

答案 0 :(得分:0)

尝试如下:

const schedule = new Date();  
    
   schedule.setHours(19);
   schedule.setMinutes(45);

   Notifications.scheduleNotificationAsync({
     content: {
     title: "title txt",
     body: 'body text',
     },
     trigger:{
       schedule,
       repeats: true,
     });