-2

我已集成HealthKit到我的应用程序中。但是当我授权时HealthKitStore,它不允许我授权。这是我用来授权的代码HealthKitStore

 var healthStore: HKHealthStore = HKHealthStore()

 let dataTypesToWrite = [
  HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass),
  HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight),
  HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMassIndex)
]

let dataTypesToRead = [
  HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierDateOfBirth),
  HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBiologicalSex),
  HKObjectType.characteristicTypeForIdentifier(HKQuantityTypeIdentifierStepCount)
]

healthStore.requestAuthorizationToShareTypes(Set<NSObject>(arrayLiteral: dataTypesToWrite),
  readTypes: Set<NSObject>(arrayLiteral: dataTypesToRead), completion: {
    (success, error) in
    if success {
      println("User completed authorisation request.")
    } else {
      println("The user cancelled the authorisation request. \(error)")
    }
})

但是当我运行我的应用程序时,我收到以下错误:

2015-05-11 12:40:59.682 HKTutorial[1036:362577] -[Swift._SwiftDeferredNSArray _allowAuthorizationForSharingWithEntitlements:]: unrecognized selector sent to instance 0x170237d80
2015-05-11 12:40:59.683 HKTutorial[1036:362577] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Swift._SwiftDeferredNSArray _allowAuthorizationForSharingWithEntitlements:]: unrecognized selector sent to instance 0x170237d80'
*** First throw call stack:
(0x18532c2d8 0x196b500e4 0x1853333a4 0x185330154 0x185232ccc 0x186444cc8 0x186444afc 0x1864151f4 0x186414e38 0x186414d4c 0x10003c858 0x10003d35c 0x10003d4a4 0x189e95474 0x189f4f790 0x189df0240 0x189d606ec 0x1852e42a4 0x1852e1230 0x1852e1610 0x18520d2d4 0x18ea236fc 0x189dd2fac 0x100022198 0x1971cea08)
libc++abi.dylib: terminating with uncaught exception of type NSException
4

1 回答 1

2

该异常表明您正在传递一个包含HKObjectTypesto数组的 Set HealthKit。它应该是一组HKObjectTypes.

于 2015-05-11T23:52:32.357 回答