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

Bog*_*riu 2 notifications local react-native expo

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

  • package.json 中的相关部分
"expo": "~40.0.0",
"expo-notifications": "~0.8.2",
Run Code Online (Sandbox Code Playgroud)
  • 我可以使用此 sipets 创建通知
"expo": "~40.0.0",
"expo-notifications": "~0.8.2",
Run Code Online (Sandbox Code Playgroud)
  • 这就是在其他方面的使用方式
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,
    },
  };
}
Run Code Online (Sandbox Code Playgroud)

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

小智 5

来自Notifications.types.d.ts

export interface DailyTriggerInput {
    channelId?: string;
    hour: number;
    minute: number;
    repeats: true;
}
Run Code Online (Sandbox Code Playgroud)

您可以使用:

trigger: {
    hour: 19;
    minute: 45;
    repeats: true;
}
Run Code Online (Sandbox Code Playgroud)