Health app displays devices in Sources tab. I'd simply like to get the same information that the Health app is using to determine the type of source.
HKSource doesn't seem to provide that.
Is there any other way to identify which source is an iPhone or Apple Watch?
let sampleType = HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)
let query = HKSourceQuery(sampleType: sampleType!, samplePredicate: nil) {
query, sources, error in
}
HKHealthStore().execute(query)
I found solution. I will query HKSample and property HKDevice in HKSample contain information about device.
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()
}