我们在HealthKit权限对话框中遇到问题。它在IOS 13中工作,但在IOS 14.6中不提示。请帮帮我
下面是代码
func requestHealthKitAuthorization() {
let healthStore = HKHealthStore()
let workoutType = HKObjectType.workoutType()
let heartRateType = HKObjectType.quantityType(forIdentifier: .heartRate)
let heartRateType1 = HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)
let heartRateType2 = HKObjectType.quantityType(forIdentifier: .stepCount)
let heartRateType3 = HKObjectType.quantityType(forIdentifier: .distanceWalkingRunning)
//reading
let readingTypes = Set([heartRateType!,heartRateType1!,heartRateType2!,heartRateType3!, workoutType])
//writing
let writingTypes = Set([heartRateType!,heartRateType1!,heartRateType2!,heartRateType3!, workoutType])
//auth request
healthStore.requestAuthorization(toShare: writingTypes, read: readingTypes) { (success, error) -> Void in
if error != nil {
print("error \(String(describing: error?.localizedDescription))")
} else if success {
print("success")
// self.startButton.setEnabled(true)
} else if !success {
print("fail")
// self.startButton.setEnabled(false)
}
}
}
1条答案
按热度按时间f0brbegy1#
回答有点晚,但可能权利是不正确的。出于某种原因,当你从Xcode中选择功能时-它添加了,它应该只是一个值。
而不是:
必须是:
感谢Matthew-Pitzer,我在这里找到了这个