-2

I have integrated HealthKit in my app. But when i do authorisation of HealthKitStore, it won't allow me to authorised. Here is the code that i have used to authorise 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)")
    }
})

But when i run my app, i get the following 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
Jay Bhalani
  • 4,142
  • 8
  • 37
  • 50
Kirti Parghi
  • 1,142
  • 3
  • 14
  • 31

1 Answers1

2

That exception indicates that you are passing a Set containing an array of HKObjectTypes to HealthKit. It should be a Set of HKObjectTypes.

Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136
Allan
  • 7,039
  • 1
  • 16
  • 26