简体   繁体   English

Swift:“不允许共享以下类型的授权:HKQuantityTypeIdentifierAppleExerciseTime”

[英]Swift: 'Authorization to share the following types is disallowed: HKQuantityTypeIdentifierAppleExerciseTime'

I am trying to use healthkit roughly following this tutorial ( https://www.raywenderlich.com/86336/ios-8-healthkit-swift-getting-started ) but requiring a different HKQuantityTypeIdentifier. 我正在尝试大致按照本教程( https://www.raywenderlich.com/86336/ios-8-healthkit-swift-getting-started )使用healthkit,但是需要使用其他HKQuantityTypeIdentifier。 Code in HealthKitManager class: HealthKitManager类中的代码:

import Foundation
import UIKit
import HealthKit

class HealthKitManager {

let healthKitStore:HKHealthStore = HKHealthStore()

func authorizeHealthKit(completion: ((_ success:Bool, _ error:NSError?) -> Void)!)
{


    let healthKitTypesToWrite: Set<HKSampleType> = [
        HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.appleExerciseTime)!
    ]
    let healthKitTypesToRead: Set<HKObjectType> = [
        HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.appleExerciseTime)!
    ]


    // If the store is not available (for instance, iPad) return an error and don't go on.
    if !HKHealthStore.isHealthDataAvailable()
    {
        let error = NSError(domain: "com.example", code: 2, userInfo: [NSLocalizedDescriptionKey:"HealthKit is not available in this Device"])
        if( completion != nil )
        {
            completion?(false, error)

        }
        return;
    }
    healthKitStore.requestAuthorization(toShare: healthKitTypesToWrite, read: healthKitTypesToRead) { (success, error) -> Void in

        completion?(success, error! as NSError)
    }

}

} }

and in the ViewController trying to call healthKit: 并在ViewController中尝试调用healthKit:

let healthManager:HealthKitManager = HealthKitManager()


func authorizeHealthKit() {
    print("1")
    healthManager.authorizeHealthKit { (authorized,  error) -> Void in
        if authorized {
            print("HealthKit authorization received.")
        }
        else
        {
            print("HealthKit authorization denied!")
            if error != nil {
                print("\(error)")
            }
        }
    }
}

However when calling authorizeHealthKit I am getting the error: 'NSInvalidArgumentException', reason: 'Authorization to share the following types is disallowed: HKQuantityTypeIdentifierAppleExerciseTime'. 但是,当调用authorizeHealthKit时,出现错误:“ NSInvalidArgumentException”,原因:不允许共享以下类型的授权:HKQuantityTypeIdentifierAppleExerciseTime。 The print "1" statement is called before the crash. 在崩溃之前调用print“ 1”语句。

Your app is not allowed request authorization to write HKQuantityTypeIdentifier.appleExerciseTime since the definition of that type is proprietary to Apple. 不允许您的应用请求编写HKQuantityTypeIdentifier.appleExerciseTime授权,因为该类型的定义是Apple专有的。 You should remove that HKQuantityType from healthKitTypesToWrite . 您应该删除HKQuantityTypehealthKitTypesToWrite

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM