Приложение «Здоровье» отображает устройства на вкладке «Источники». Я просто хотел бы получить ту же информацию, которую приложение Health использует для определения типа источника.
HKSource, похоже, этого не обеспечивает.
Есть ли другой способ определить, какой источник - iPhone или Apple Watch?
let sampleType = HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)
let query = HKSourceQuery(sampleType: sampleType!, samplePredicate: nil) {
query, sources, error in
}
HKHealthStore().execute(query)





Я нашел решение. Я запрошу HKSample, а свойство HKDevice в HKSample будет содержать информацию об устройстве.
let group = DispatchGroup()
for source in sources {
let sourceModel = SourceHealthKitModel(source: source)
group.enter()
let type = HKQuantityType.quantityType(forIdentifier: .stepCount)
let predicate = HKQuery.predicateForObjects(from: source)
let query = HKSampleQuery(sampleType: type!, predicate: predicate, limit: 1, sortDescriptors: nil) { (query, results, error) in
if let sample = results?.first {
sourceModel.sample = sample
self?.dataSources.append(sourceModel)
}
group.leave()
}
HKHealthStore().execute(query)
}
group.notify(queue: .main) {
self?.tableView.reloadData()
}