Reputation: 6849
Using iOS 10, first beta, HealthKit authorization crashes. With code that was running with iOS 9.x (except that I changed to Swift 3)
even the most simple authorization crashes:
func authorizeHealthKit(_ completion: ((success:Bool, error:NSError?) -> Void)!)
{
// 1. Set the types you want to read from HK Store
var healthKitTypesToRead: Set<HKObjectType> = Set<HKObjectType>()
healthKitTypesToRead.insert(HKObjectType.characteristicType(forIdentifier: HKCharacteristicTypeIdentifier.dateOfBirth)!)
// 2. Set the types you want to write to HK Store
var healthKitTypesToWrite: Set<HKSampleType> = Set<HKSampleType>()
// 3. If the store is not available (for instance, iPad) return an error and don't go on.
if !HKHealthStore.isHealthDataAvailable()
{
// do some error handling
return;
}
// 4. Request HealthKit authorization
// iOS 10 beta 1 throws NSException without declaring it:
healthStore.requestAuthorization(toShare: healthKitTypesToWrite, read: healthKitTypesToRead) { (success: Bool, error: NSError?) -> Void in
// do stuff
}
}
this is the simplest code that crashes in iPhone SE simulator with iOS 10 beta 1.
The exception message is
"libc++abi.dylib: terminating with uncaught exception of type NSException".
Is it possible that authorization does not work at all with iOS 10 beta 1? This is XCode 8 beta 1
What works: my HelthKit App that I built using Xcode 7.3 with iOS 9.3 target runs fine under iOS 10 beta 1 on hardware iPhone 5.
Upvotes: 10
Views: 3151
Reputation: 3506
From the Apple Documentation:
An iOS app linked on or after iOS 10.0 must include in its Info.plist file the usage description keys for the types of data it needs to access or it will crash. To access and update HealthKit data specifically, it must include the
NSHealthShareUsageDescription
andNSHealthUpdateUsageDescription
keys, respectively.
Upvotes: 7
Reputation: 7353
The message of the exception should give you a hint about what the issue is. Starting in iOS 10, usage strings that describe why your app would like access to the users HealthKit data are required. You can specify them in your app's Info.plist.
Upvotes: 15