feat: 添加测试通知功能以验证后台任务执行,记录通知发送时间

This commit is contained in:
2025-09-07 10:09:08 +08:00
parent aaa34a7a07
commit df7f04808e

View File

@@ -126,6 +126,36 @@ async function executeStandReminderTask(): Promise<void> {
}
}
// 发送测试通知以验证后台任务执行
async function sendTestNotification(): Promise<void> {
try {
console.log('发送后台任务测试通知...');
const Notifications = await import('expo-notifications');
// 发送简单的测试通知
await Notifications.scheduleNotificationAsync({
content: {
title: '后台任务测试',
body: `后台任务正在执行中... 时间: ${new Date().toLocaleTimeString()}`,
data: {
type: 'background_task_test',
timestamp: Date.now()
}
},
trigger: null, // 立即发送
});
console.log('后台任务测试通知发送成功');
// 记录测试通知发送时间
await AsyncStorage.setItem('@last_background_test_notification', Date.now().toString());
} catch (error) {
console.error('发送测试通知失败:', error);
}
}
// 后台任务执行函数
async function executeBackgroundTasks(): Promise<void> {
console.log('开始执行后台任务...');
@@ -138,6 +168,9 @@ async function executeBackgroundTasks(): Promise<void> {
return;
}
// 发送测试通知以验证任务是否正在执行
await sendTestNotification();
// 执行喝水提醒检查任务
await executeWaterReminderTask();