ios 向Heathkit提示授权请求

ssgvzors  于 2023-10-21  发布在  iOS
关注(0)|答案(1)|浏览(127)

我们在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)
        }
    }
}
f0brbegy

f0brbegy1#

回答有点晚,但可能权利是不正确的。出于某种原因,当你从Xcode中选择功能时-它添加了,它应该只是一个值。
而不是:

<key>com.apple.developer.healthkit.access</key>
<array/>

必须是:

<key>com.apple.developer.healthkit</key>
<true/>

感谢Matthew-Pitzer,我在这里找到了这个

相关问题