我在我的应用中集成了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
答案 0 :(得分:2)
该异常表示您正在将包含HKObjectTypes
数组的Set传递给HealthKit
。它应该是一组HKObjectTypes
。