Swift 请求HealthKit isn'的授权;没有执行。(HKHealthStore().requestAuthorization)

Swift 请求HealthKit isn'的授权;没有执行。(HKHealthStore().requestAuthorization),swift,healthkit,Swift,Healthkit,我目前正在尝试制作一个简单的计步器应用程序。 然而,我似乎无法获得使用HealthKit的授权 我有这段代码试图获得权限,然后使用回调来处理结果 func authorizeHealthKit(withCallback: @escaping (Bool, Error?) -> ()) { // 3. If the store is not available (for instance, iPad) return an error and don't go on. if !

我目前正在尝试制作一个简单的计步器应用程序。 然而,我似乎无法获得使用HealthKit的授权

我有这段代码试图获得权限,然后使用回调来处理结果

func authorizeHealthKit(withCallback: @escaping (Bool, Error?) -> ())
{
    // 3. If the store is not available (for instance, iPad) return an error and don't go on.
    if !HKHealthStore.isHealthDataAvailable() {
        let error = NSError(domain: "health_tracker", code: 2, userInfo: [NSLocalizedDescriptionKey: "HealthKit is not available in this Device"])
        print(error)
    }
    else {
        // 4.  Request HealthKit authorization
        self._healthKitStore.requestAuthorization(toShare: _healthKitTypesToWrite, read: _healthKitTypesToRead) { (success, error) -> Void in
            self.isAuthorized = success
            withCallback(success, error)
        }
    }
}
然而,出于某种原因,iOS似乎完全跳过了这条线。在回调函数(即
authorizeHealthKit
调用)上设置断点时,不会发生任何事情,也不会停止。当使用Step Over时,它只跳过这些行。我的模拟器(和irl iPhone)的屏幕是白色的,没有弹出对话

知道为什么会这样吗? 我做错什么了吗


其他信息:

同一班级(HealthKitManager.swift)

也发生在我身上。 通过将我的手机升级到iOS 11.3.1解决了这个问题。
请注意,即使使用较低的iOS,它也能在模拟器上顺利工作,所以我猜这是一个xcode错误,升级到最新的xcode版本也能解决它……

似乎在xcode 10.1和配套模拟器上发生了。现在,当我添加一个单步示例时,它可以工作(某种程度上)。运行状况确实会在模拟器上崩溃,并出现看门狗错误,但至少我得到了requestAuthorizations屏幕。
let _healthKitStore: HKHealthStore = HKHealthStore()
var isAuthorized: Bool = false
let _healthKitTypesToWrite: Set<HKSampleType> = [
    HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)!
]

let _healthKitTypesToRead: Set<HKSampleType> = [
    HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)!
]
let _healthKitManager = HealthKitManager()
(...)
if !_healthKitManager.isAuthorized {
            _healthKitManager.authorizeHealthKit(withCallback: onAuthenticationResult)
        }
(...)
func onAuthenticationResult(success: Bool, error: Error?) {
    print("Authentication result: ", success.description)
}