I wish to restrict results returned from a HealthKit HKSampleQuery to those that have been input through my own app. Is there a way to specify results only with my application bundle identifier, and thereby exclude any other data sources returned from other applications?
Is there a way to specify this with an NSSortDescriptor
or NSPredicate
, as I have tried below?
func querySteps() {
// let sort = NSSortDescriptor(key: "bundleIdentifier", ascending: true, selector: "com.companyName.appName:")
// let resultPredicate = NSPredicate(format: "bundleIdentifier", "com.companyName.appName")
let sampleQuery = HKSampleQuery(sampleType: healthKitManager.stepsCount!,
predicate: nil,
limit: 100,
sortDescriptors: nil)
{ [unowned self] (query, results, error) in
if let results = results as? [HKQuantitySample] {
self.steps = results
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.reloadData()
});
}
}
healthStore?.executeQuery(sampleQuery)
}