2015-05-11 55 views
-2

我已經在我的應用程序中集成了HealthKit。但是,當我做授權HealthKitStore,它不會允許我授權。 這裏是我用來授權HealthKitStore代碼:iOS8應用程序在Xcode6.3上崩潰時授權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 

回答

2

這異常指示要傳遞包含一組一排HKObjectTypesHealthKit。它應該是一組HKObjectTypes

相關問題