feat(healthkit): 实现HealthKit与服务端的双向数据同步,包括身高、体重和出生日期的获取与保存
This commit is contained in:
@@ -14,6 +14,30 @@ Notifications.setNotificationHandler({
|
||||
}),
|
||||
});
|
||||
|
||||
/**
|
||||
* 清除应用角标
|
||||
*/
|
||||
export async function clearBadgeCount(): Promise<void> {
|
||||
try {
|
||||
await Notifications.setBadgeCountAsync(0);
|
||||
console.log('✅ 应用角标已清除');
|
||||
} catch (error) {
|
||||
console.error('❌ 清除应用角标失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前角标数量
|
||||
*/
|
||||
export async function getBadgeCount(): Promise<number> {
|
||||
try {
|
||||
return await Notifications.getBadgeCountAsync();
|
||||
} catch (error) {
|
||||
console.error('❌ 获取角标数量失败:', error);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
export interface NotificationData {
|
||||
title: string;
|
||||
body: string;
|
||||
@@ -110,6 +134,9 @@ export class NotificationService {
|
||||
return;
|
||||
}
|
||||
|
||||
// 清除应用角标(应用启动时)
|
||||
await clearBadgeCount();
|
||||
|
||||
// 设置通知监听器
|
||||
this.setupNotificationListeners();
|
||||
|
||||
@@ -151,6 +178,9 @@ export class NotificationService {
|
||||
|
||||
console.log('处理通知点击:', data);
|
||||
|
||||
// 用户点击通知后清除角标
|
||||
clearBadgeCount();
|
||||
|
||||
// 根据通知类型处理不同的逻辑
|
||||
if (data?.type === 'workout_reminder') {
|
||||
// 处理运动提醒
|
||||
|
||||
Reference in New Issue
Block a user