gpt4 book ai didi

swift - HealthKit 授权在 iOS 10 beta 1 中因未处理的 NSException 而崩溃

转载 作者:IT王子 更新时间:2023-10-29 05:34:19 24 4
gpt4 key购买 nike

使用 iOS 10,第一个测试版,HealthKit 授权崩溃。使用与 iOS 9.x 一起运行的代码(除了我更改为 Swift 3)

即使是最简单的授权也会崩溃:

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
}
}

这是在 iOS 10 beta 1 的 iPhone SE 模拟器中崩溃的最简单的代码。

异常信息是

"libc++abi.dylib: terminating with uncaught exception of type NSException".

授权是否可能根本不适用于 iOS 10 beta 1?这是 XCode 8 beta 1

什么有效:我使用 Xcode 7.3 和 iOS 9.3 目标构建的 HelthKit 应用程序在硬件 iPhone 5 上的 iOS 10 beta 1 下运行良好。

最佳答案

异常消息应该会提示您问题是什么。从 iOS 10 开始,描述您的应用为何希望访问用户 HealthKit 数据的使用字符串是必需的。您可以在应用的 Info.plist 中指定它们。

关于swift - HealthKit 授权在 iOS 10 beta 1 中因未处理的 NSException 而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37841819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com