首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >苹果HealthKit HKHealthStore.requestAuthorization()返回错误

苹果HealthKit HKHealthStore.requestAuthorization()返回错误
EN

Stack Overflow用户
提问于 2022-05-23 23:21:44
回答 1查看 188关注 0票数 0

我正在尝试访问一些HealthKit数据,但得到了“无效类型标识符数组”错误。我在Info.plist中定义了“健康记录使用说明”、“健康共享使用说明”和“健康更新使用说明”。下面是代码片段:

代码语言:javascript
复制
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")
}

在提示批准这两个项目之后,我看到:

代码语言:javascript
复制
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)}

为什么我看到“无效类型标识符数组”错误?

EN

回答 1

Stack Overflow用户

发布于 2022-05-23 23:52:32

getRequestStatusForAuthorization()接受一个Set,您正在传递一个数组。我想知道为什么编译器一开始就允许您这样做,然后我想知道为什么您会收到这种奇怪的消息。你试过先把这个数组转换成一个集合吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72355709

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档