[英]Swift 4 Get preferredUnit from HealthKit
我是Swift的初学者,我尝试从HealthKit获取用户首选单位。
苹果为其提供此功能
func preferredUnits(for quantityTypes: Set<HKQuantityType>,
completion: @escaping ([HKQuantityType : HKUnit], Error?) -> Void)
但是我真的不知道如何正确实施它。 Atm的功能在我的App中什么也不做。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let bloodGlucose = HKObjectType.quantityType(forIdentifier: .bloodGlucose)
let HKQuantitySet: Set<HKSampleType> = [bloodGlucose!]
self.preferredUnits(for: HKQuantitySet as! Set<HKQuantityType>, completion: { (preferedUnit, error) in
print(preferedUnit)
})
return true
}
func preferredUnits(for quantityTypes: Set<HKQuantityType>,
completion: @escaping ([HKQuantityType : HKUnit], Error?) -> Void){
}
我很确定我对此完全错了。
有人知道如何正确实现该功能吗? 一般而言,不仅要bloodglucose
,还不错。
您需要将preferredUnits
函数称为HKHealthStore
的实例。 您的代码只是调用您已声明且具有相同签名的函数,该函数不执行任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.