无法使用类型的参数列表调用 'requestAuthorizationToShareTypes'
Cannot invoke 'requestAuthorizationToShareTypes' with an argument list of type
它说:
Cannot invoke 'requestAuthorizationToShareTypes' with an argument list of type (HKQuantityType, readTypes: HKCharacteristicType, completion: (Bool, NSError!) -> Void)
请帮忙
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if HKHealthStore.isHealthDataAvailable() {
let healthStore = HKHealthStore()
healthStore.requestAuthorizationToShareTypes(HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)!, readTypes: (HKCharacteristicType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBiologicalSex))! , completion:{
(success:Bool,error:NSError!) -> Void in
if !success{
print("error")
}
})
}
}
requestAuthorizationForTypes
方法需要 集 ,共 HKObjectType
。试试这个:
let shareTypes : Set = [HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)!]
let readTypes : Set = [HKCharacteristicType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBiologicalSex)!]
healthStore.requestAuthorizationToShareTypes(shareTypes, readTypes:readTypes, completion: { (success, error) -> Void in
if !success{
print("error")
}
})
试试这个方法
// MARK: - HealthKit
func performAutorizationForHealthKit(var completion:((success: Bool, error: NSError!) -> Void)?) {
let healthKitTypesToShare: Set = [ HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)!]
if !HKHealthStore.isHealthDataAvailable() {
let error = NSError(domain: "com.mutualCore.healthKit", code: 1, userInfo: [NSLocalizedDescriptionKey : "HealthKit is not available in this Device"])
completion?(success: false, error: error)
completion = nil
return;
}
healthKitStore.requestAuthorizationToShareTypes(healthKitTypesToShare, readTypes: [], completion: {
(successRequest, errorRequest) -> Void in
completion?(success: successRequest, error: errorRequest)
})
}
用法
performAutorizationForHealthKit { (success, error) -> Void in
if error != nil {
print("success")
}
}
它说:
Cannot invoke 'requestAuthorizationToShareTypes' with an argument list of type (HKQuantityType, readTypes: HKCharacteristicType, completion: (Bool, NSError!) -> Void)
请帮忙
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if HKHealthStore.isHealthDataAvailable() {
let healthStore = HKHealthStore()
healthStore.requestAuthorizationToShareTypes(HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)!, readTypes: (HKCharacteristicType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBiologicalSex))! , completion:{
(success:Bool,error:NSError!) -> Void in
if !success{
print("error")
}
})
}
}
requestAuthorizationForTypes
方法需要 集 ,共 HKObjectType
。试试这个:
let shareTypes : Set = [HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)!]
let readTypes : Set = [HKCharacteristicType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBiologicalSex)!]
healthStore.requestAuthorizationToShareTypes(shareTypes, readTypes:readTypes, completion: { (success, error) -> Void in
if !success{
print("error")
}
})
试试这个方法
// MARK: - HealthKit
func performAutorizationForHealthKit(var completion:((success: Bool, error: NSError!) -> Void)?) {
let healthKitTypesToShare: Set = [ HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)!]
if !HKHealthStore.isHealthDataAvailable() {
let error = NSError(domain: "com.mutualCore.healthKit", code: 1, userInfo: [NSLocalizedDescriptionKey : "HealthKit is not available in this Device"])
completion?(success: false, error: error)
completion = nil
return;
}
healthKitStore.requestAuthorizationToShareTypes(healthKitTypesToShare, readTypes: [], completion: {
(successRequest, errorRequest) -> Void in
completion?(success: successRequest, error: errorRequest)
})
}
用法
performAutorizationForHealthKit { (success, error) -> Void in
if error != nil {
print("success")
}
}