我正在尝试访问一些HealthKit数据,但得到了“无效类型标识符数组”错误。我在Info.plist中定义了“健康记录使用说明”、“健康共享使用说明”和“健康更新使用说明”。下面是代码片段:
if HKHealthStore.isHealthDataAvailable() {
guard let allergiesType = HKObjectType.clinicalType(forIdentifier: .allergyRecord),
let medicationsType = HKObjectType.clinicalType(forIdentifier: .medicationRecord) else {
fatalError("*** Unable to create the requested types ***")
}
healthStore.getRequestStatusForAuthorization(toShare: [], read: [allergiesType, medicationsType]) { (status, error) in
if let error = error {
print("AppDelegate::getRequestStatusForAuthorization(): error=\(String(describing: error))")
return
}
switch status {
case .unnecessary:
print("Application has already sent request for Authorization")
default:
print("Unknown status for Authorization")
healthStore.requestAuthorization(toShare: [], read: [allergiesType, medicationsType]) { (success, error) in
if let error = error {
print("AppDelegate::requestAuthorization(): error=\(String(describing: error))")
return
}
guard success else {
print("AppDelegate::requestAuthorization(): success=\(String(describing: error))")
return
}
} // healthStore.requestAuthorization()
} // switch status
} // healthStore.getRequestStatusForAuthorization()
} else { // HKHealthStore.isHealthDataAvailable()
// No HealthKit on this platform
print("AppDelegate::isHealthDataAvailable() - No HealthKit on this platform")
}在提示批准这两个项目之后,我看到:
Unknown status for Authorization <= This message is seen before the authorization screen is shown
2022-05-23 15:27:41.988596-0700 myHealth[53345:4120994] [auth] FAILED prompting authorization request to share (
), read (
HKClinicalTypeIdentifierAllergyRecord,
HKClinicalTypeIdentifierMedicationRecord
)
AppDelegate::requestAuthorization(): error=Error Domain=com.apple.healthkit Code=3 "Invalid type identifier array (expected NSArray, found __NSDictionaryM)" UserInfo={NSLocalizedDescription=Invalid type identifier array (expected NSArray, found __NSDictionaryM)}为什么我看到“无效类型标识符数组”错误?
发布于 2022-05-23 23:52:32
getRequestStatusForAuthorization()接受一个Set,您正在传递一个数组。我想知道为什么编译器一开始就允许您这样做,然后我想知道为什么您会收到这种奇怪的消息。你试过先把这个数组转换成一个集合吗?
https://stackoverflow.com/questions/72355709
复制相似问题