HealthKit

Healkit框架由苹果提供,它帮助我们以易便易捷方式获取和管理用户健康相关数据

HealthKit存取Healkit数据用户数据很容易从HealthKit数据库获取用户自己决定数据用户允许访问与否

应用健康包需要遵循这些步骤

  1. 需要添加这两个信息列表
  • 隐私健康共享用法描述
  • 隐私健康更新用法描述

请求用户权限访问HealthKit数据

letStoresetSteprectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStectionStection

使用上方代码后 用户允许取步并显示类型视图屏幕

需要激活上文视图显示的阶梯权限

3级用户获得权限后,我们在此实际取用用户阶梯

func获取StepsCount:Date:@escaping-Double->Voidlet (start, end) = self.getWholeDate(date: forSpecificDate)            let predicate = HKQuery.predicateForSamples(withStart: start, end: end, options: .strictStartDate)            let query = HKStatisticsQuery(quantityType: stepsQuantityType, quantitySamplePredicate: predicate, options: .cumulativeSum) { _, result, _ in                guard let result = result, let sum = result.sumQuantity() else {                    completion(0.0)                    return                }                completion(sum.doubleValue(for: HKUnit.count()))            }                  self.healthKitStore.execute(query)        }              func getWholeDate(date : Date) -> (startDate:Date, endDate: Date) {            var startDate = date            var length = TimeInterval()            _ = Calendar.current.dateInterval(of: .day, start: &startDate, interval: &length, for: startDate)            let endDate:Date = startDate.addingTimeInterval(length)            return (startDate,endDate)        }

调用上方函数可获取日期

stepsCount/ServerQue.main{sy

取心机始始始至终

可选级数( 300.0)

以此计算阶梯穿透HealthKit也可以通过HealthKit计算心电网、卡路里和其他元素

库多斯

留答题