Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HealthKit authorization crashes with unhandled NSException in iOS 10 beta 1

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.

like image 317
Gerd Castan Avatar asked Jun 15 '16 17:06

Gerd Castan


1 Answers

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.

like image 97
Allan Avatar answered Oct 26 '22 01:10

Allan