feat(healthkit): 实现HealthKit与服务端的双向数据同步,包括身高、体重和出生日期的获取与保存
This commit is contained in:
@@ -5,6 +5,7 @@ import { useColorScheme } from '@/hooks/useColorScheme';
|
||||
import { useCosUpload } from '@/hooks/useCosUpload';
|
||||
import { useI18n } from '@/hooks/useI18n';
|
||||
import { useSafeAreaTop } from '@/hooks/useSafeAreaWithPadding';
|
||||
import { syncServerToHealthKit } from '@/services/healthKitSync';
|
||||
import { fetchMyProfile, updateUserProfile } from '@/store/userSlice';
|
||||
import { fetchMaximumHeartRate } from '@/utils/health';
|
||||
import AsyncStorage from '@/utils/kvStore';
|
||||
@@ -212,6 +213,18 @@ export default function EditProfileScreen() {
|
||||
}));
|
||||
// 拉取最新用户信息,刷新全局状态
|
||||
await dispatch(fetchMyProfile() as any);
|
||||
|
||||
// 同步身高、体重到 HealthKit
|
||||
console.log('开始同步个人健康数据到 HealthKit...');
|
||||
const syncSuccess = await syncServerToHealthKit({
|
||||
height: next.height,
|
||||
weight: next.weight,
|
||||
birthDate: next.birthDate ? new Date(next.birthDate).getTime() / 1000 : undefined
|
||||
});
|
||||
|
||||
if (syncSuccess) {
|
||||
console.log('个人健康数据已同步到 HealthKit');
|
||||
}
|
||||
} catch (e: any) {
|
||||
// 接口失败不阻断本地保存
|
||||
console.warn('更新用户信息失败', e?.message || e);
|
||||
|
||||
Reference in New Issue
Block a user