com.apple.healthkit, код 4, неавторизованная ошибка при получении в приложении для часов Swift для Apple - PullRequest
0 голосов
/ 30 января 2020

Я работаю над приложением тренировки в Apple watch. Раньше все работало нормально, Внезапно выдавала ошибку, как показано ниже

com.apple.healthkit code 4, Ошибка «Не авторизовано» при получении приложения для часов Swift для Apple и ничего не происходило позже.

Но, раньше работал. Я проверяю симулятор. Просто я беру пользователя пешком и ударов в минуту за 6 минут ходьбы.

    let typesToRead: Set = [
        HKQuantityType.quantityType(forIdentifier: .heartRate)!,
        HKQuantityType.quantityType(forIdentifier: .distanceWalkingRunning)!
    ]

    let healthKitTypes: Set = [
        HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.heartRate)!,
        HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.distanceWalkingRunning)!
    ]

override func awake(withContext context: Any?) {
    super.awake(withContext: context)
    // Configure interface objects here.
    healthStore.requestAuthorization(toShare: healthKitTypes, read: typesToRead) { (success, error) in
        if success {
            print("Access Success")
            self.configuration = HKWorkoutConfiguration()
            self.configuration.activityType = .walking
            do {
                self.session = try HKWorkoutSession(healthStore: self.healthStore, configuration: self.configuration)
                print("session called")
                } catch {
                    return
                }

            self.builder = self.session?.associatedWorkoutBuilder()
            self.session!.delegate = self
            self.builder!.delegate = self
            self.builder!.dataSource = HKLiveWorkoutDataSource(healthStore: self.healthStore,
                                                               workoutConfiguration: self.configuration)
            self.session!.startActivity(with: Date())
            self.startTimer()
            self.builder?.beginCollection(withStart: Date()) { (success, error) in
                    if success {
                        print("Collecting data started")
                    } else {
                        self.invalidateSession()
                        self.showAlert(withTitle: "Alert", andMessage: error!.localizedDescription)
                    }
                }
        } else {
            print("error authorizating HealthStore \(error?.localizedDescription)")
        }
    }
}

Есть предложения?

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...