问题描述
我正在尝试使用HealthKit读取一天的步骤数据。 HK认为即使我的代码中没有写入或请求HK写入授权的内容,我也在某种程度上尝试写入它。
这是我用于请求的代码:
let healthKitTypes: Set = [
HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)!
]
healthStore.requestAuthorization(toShare: healthKitTypes,read: healthKitTypes) { (isSuccess,error) in
if isSuccess {
UserDefaults.standard.set(true,forKey: "isHKAuthorized")
} else { UserDefaults.standard.set(false,forKey: "isHKAuthorized") }
if let error = error {
UserDefaults.standard.set(false,forKey: "isHKAuthorized")
print(error.localizedDescription)
}
}
我如何才能让HK不再烦扰我有关写权限的问题? auth UI应该只要求读取数据。
解决方法
身份验证请求显示“ toShare”,但这意味着编写。因此,将toShare参数设置为nil或一个空集。