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

教學連結

Memo

  • 非手動輸入

  • 手動輸入

Create Multiple predicate

教學連結

獲取統計數據

教學連結

Memo

  • 心率單位

Last updated

Was this helpful?