如何解决必须将NSHealthUpdateUsageDescription设置为请求HKQuantityTypeIdentifierStepCount的写授权
我正在尝试使用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或一个空集。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。