参考HealthKit -ClinicalHealthRecords,我们实现了以下方法来获取用户的临床记录,但似乎查询失败了,而且每次应用程序都会崩溃。没有生成崩溃报告,因为在查询数据之后,应用程序就会崩溃。
我们在Apple提供的示例帐户中尝试了同样的方法,它在模拟器中运行良好,但它与实际用户崩溃。
下面是我们使用这个苹果公司的文章创建的代码片段
func getRecordsForCHRType(type: HKClinicalTypeIdentifier, completion:@escaping ([HKClinicalRecord]?) -> Void) {
guard let healthRecordType = HKObjectType.clinicalType(forIdentifier: type) else { return }
let startDate = Calendar.current.date(byAdding: DateComponents(day: -365), to: Date())!
let endDate = Calendar.current.date(byAdding: DateComponents(day: 0), to: Date())!
let predicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate, options: [.strictStartDate])
let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: false)
let healthRecordQuery = HKSampleQuery(sampleType: healthRecordType, predicate: predicate, limit: 0, sortDescriptors: [sortDescriptor]) { (query, samples, error) in
guard let actualSamples = samples else {
completion(nil)
return
}
let healthRecordSamples = actualSamples as? [HKClinicalRecord]
completion(healthRecordSamples)
}
HKHealthStore().execute(healthRecordQuery)
}你能帮我们找出这个问题吗?
另外,请帮助我们了解临床健康记录样本JSON中提供的以下不同类型的日期(详细信息),是否可以在这些日期上应用筛选器来缩小临床记录响应范围?
任何帮助都将不胜感激!
发布于 2021-11-29 15:57:29
有人在https://developer.apple.com/forums/thread/695189上发布了同样的问题
崩溃肯定不会发生,您能在这里粘贴堆栈跟踪吗?
关于日期,这在很大程度上取决于您解析的资源类型以及数据模型中实际填充的日期,这取决于数据来源。“开始日期”和“结束日期”有不同的含义,参见https://developer.apple.com/documentation/healthkit/hkclinicalrecord的文档
注意,该记录继承了HKSample类的startDate和endDate属性。但是,系统不使用来自FHIR数据的信息填充这些属性;相反,startDate和endDate反映了系统将FHIR数据下载到设备的时间和日期。
https://stackoverflow.com/questions/70153379
复制相似问题