我很难弄清楚expo的最新版本,如何在一天中的特定时间设置本地通知,并使其每天重复。
- package.json中的相关部分
"expo": "~40.0.0",
"expo-notifications": "~0.8.2",
- 我可以使用此sipets创建通知
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());
如何在明天的特定时间开始通知,并每天重复?
来自Notifications.types.d.ts
export interface DailyTriggerInput {
channelId?: string;
hour: number;
minute: number;
repeats: true;
}
您可以使用:
trigger: {
hour: 19;
minute: 45;
repeats: true;
}
尝试如下:
const schedule = new Date();
schedule.setHours(19);
schedule.setMinutes(45);
Notifications.scheduleNotificationAsync({
content: {
title: "title txt",
body: 'body text',
},
trigger:{
schedule,
repeats: true,
});