feat(workout): 新增锻炼历史记录功能与健康数据集成
- 新增锻炼历史页面,展示最近一个月的锻炼记录详情 - 添加锻炼汇总卡片组件,在统计页面显示当日锻炼数据 - 集成HealthKit锻炼数据获取,支持多种运动类型和详细信息 - 完善锻炼数据处理工具,包含统计分析和格式化功能 - 优化后台任务,随机选择挑战发送鼓励通知 - 版本升级至1.0.16
This commit is contained in:
@@ -125,6 +125,8 @@ async function executeChallengeReminderTask(): Promise<void> {
|
||||
|
||||
const todayKey = new Date().toISOString().slice(0, 10);
|
||||
|
||||
// 筛选出需要发送通知的挑战(未签到且今天未发送过通知)
|
||||
const eligibleChallenges = [];
|
||||
for (const challenge of joinedChallenges) {
|
||||
const progress = challenge.progress;
|
||||
if (!progress || progress.checkedInToday) {
|
||||
@@ -137,17 +139,30 @@ async function executeChallengeReminderTask(): Promise<void> {
|
||||
continue;
|
||||
}
|
||||
|
||||
eligibleChallenges.push(challenge);
|
||||
}
|
||||
|
||||
// 如果有符合条件的挑战,随机选择一个发送通知
|
||||
if (eligibleChallenges.length > 0) {
|
||||
const randomIndex = Math.floor(Math.random() * eligibleChallenges.length);
|
||||
const selectedChallenge = eligibleChallenges[randomIndex];
|
||||
|
||||
try {
|
||||
await ChallengeNotificationHelpers.sendEncouragementNotification({
|
||||
userName,
|
||||
challengeTitle: challenge.title,
|
||||
challengeId: challenge.id,
|
||||
challengeTitle: selectedChallenge.title,
|
||||
challengeId: selectedChallenge.id,
|
||||
});
|
||||
|
||||
const storageKey = `@challenge_encouragement_sent:${selectedChallenge.id}`;
|
||||
await AsyncStorage.setItem(storageKey, todayKey);
|
||||
|
||||
console.log(`已随机选择并发送挑战鼓励通知: ${selectedChallenge.title}`);
|
||||
} catch (notificationError) {
|
||||
console.error('发送挑战鼓励通知失败:', notificationError);
|
||||
}
|
||||
} else {
|
||||
console.log('没有符合条件的挑战需要发送鼓励通知');
|
||||
}
|
||||
|
||||
console.log('挑战鼓励提醒后台任务完成');
|
||||
|
||||
Reference in New Issue
Block a user