diff --git a/services/backgroundTaskManager.ts b/services/backgroundTaskManager.ts index 71af81a..22b850f 100644 --- a/services/backgroundTaskManager.ts +++ b/services/backgroundTaskManager.ts @@ -126,6 +126,36 @@ async function executeStandReminderTask(): Promise { } } +// 发送测试通知以验证后台任务执行 +async function sendTestNotification(): Promise { + 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 { console.log('开始执行后台任务...'); @@ -138,6 +168,9 @@ async function executeBackgroundTasks(): Promise { return; } + // 发送测试通知以验证任务是否正在执行 + await sendTestNotification(); + // 执行喝水提醒检查任务 await executeWaterReminderTask();