【发布时间】:2016-06-15 17:17:21
【问题描述】:
使用 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: 以未捕获的类型异常终止 NSException”。
授权在 iOS 10 beta 1 中是否可能根本不起作用? 这是 XCode 8 beta 1
什么有效:我使用 Xcode 7.3 和 iOS 9.3 目标构建的 HelthKit 应用程序在硬件 iPhone 5 上的 iOS 10 beta 1 下运行良好。
【问题讨论】:
-
对不起,不知道这里有什么解决方案,但只是想回应一下我在 Objective C 中遇到了同样的问题。似乎在 Watch Simulator 上工作正常,但不幸的是访问健康数据手表首先需要 iPhone 应用程序的授权。我正在使用 iPhone 应用程序模拟器,我遇到了同样的崩溃。这可能是 beta 1 的错误吗?虽然它没有在发行说明中提及。
-
您的问题解决了吗?在最新版本(Beta 6)中,我在
healthStore.requestAuthorization中放入完成处理程序的方括号后立即收到内部错误 -
是的,公认的答案就是解决方案
-
顺便说一句,还有其他原因会导致相同的崩溃:例如,如果您尝试在锻炼分钟内获得写入权限,您会得到完全相同的崩溃,但没有任何文本。