HealthKit
教學連結
Memo
三大重點:取得資料授權、讀、寫
How to request permission and access HealthKit data
How to read HealthKit data
How to write data to HealthKit’s central repository
授權
//3. Prepare a list of types you want HealthKit to read and write
let healthKitTypesToWrite: Set<HKSampleType> = [bodyMassIndex,
activeEnergy,
HKObjectType.workoutType()]
let healthKitTypesToRead: Set<HKObjectType> = [dateOfBirth,
bloodType,
biologicalSex,
bodyMassIndex,
height,
bodyMass,
HKObjectType.workoutType()]
//4. Request Authorization
HKHealthStore().requestAuthorization(toShare: healthKitTypesToWrite,
read: healthKitTypesToRead) { (success, error) in
completion(success, error)
}讀
寫
Tell if data was user entered manually
教學連結
Detect if HealthKit activity has been entered manually
The bundle identifier of the entry if made manually will be com.apple.Health, which is the bundle identifier of the Health app. Notice the capital H. When you pull your data just ignore the data which has a bundle identifier of com.apple.Health.
That way you will be only considering activities which are not manual
Memo
非手動輸入
手動輸入
Create Multiple predicate
教學連結
HealthKit: create a predicate for specific sources and date range
Use NSCompoundPredicate
獲取統計數據
教學連結
Memo
心率單位
Last updated
Was this helpful?