我正在使用Expo v28,我想每天向用户发送通知。 (他们选择时间,必须接受;))
我当时在考虑使用Notifications of Expo中的scheduleLocalNotificationAsync,但是我对文档及其开发感到有些困惑。
这是我到目前为止所做的:
const result = await Permissions.askAsync(Permissions.NOTIFICATIONS);
if (result.status === "granted") {
Notifications.cancelAllScheduledNotificationsAsync();
const localNotification = {
title: "A",
body: "B"
android: {
priority: "high",
vibrate: true
}
};
const date = DailySentenceStore.answerStep3Date;
date.setDate(date.getDate() + 1);
const schedulingOptions = {
repeat: "day",
date
};
Notifications.scheduleLocalNotificationAsync(localNotification, schedulingOptions);
Notifications.addListener(this.listener);
}
我在当前日期添加了一天,因为我希望它从第二天开始。
显然,这真的很难测试……(我必须等待1天,看看它是否会重复出现)
我是在正确的轨道上还是应该创建100条时间表通知,每次添加1天?
我不确定既不必添加侦听器,还是应该添加?在侦听器中,我必须执行presentLocalNotificationAsync?