Questions tagged [hksamplequery]

HKSampleQuery is an API included in Apple's iOS HealthKit framework that provides a way to search for specific aspects of a user's health data.

From Apple's documentation:

HealthKit uses sample queries to search for sample data in the HealthKit store. You can use sample queries to search for any concrete subclasses of the HKSample class, including HKCategorySample, HKCorrelation, HKQuantitySample, and HKWorkout objects.

59 questions
2
votes
1 answer

Reading steps for date intervals from HealthKit using Swift

I have this method to read today steps from HealthKit. func todaySteps(completion: (Double, NSError?) -> () ) { // this function gives you all of the steps the user has taken since the beginning of the current day. let type =…
Byte
  • 629
  • 2
  • 11
  • 29
2
votes
3 answers

How to access metaData of workout in healthkit using Swift

I am able to get basic data of activities like duration, totalEnergyBurned etc. But how can I access meta data like HKWasUserEntered startDate ? Here is my code so far var predicate =…
Byte
  • 629
  • 2
  • 11
  • 29
2
votes
1 answer

how to use health kit sample query in progressive ways

I really want the results from executing a HKSampleQuery. But, I always cannot get the results right after executing the query. My case is below (error processing code is deleted): let sortDescriptor = NSSortDescriptor(key:…
jeongmin.cha
  • 768
  • 8
  • 22
2
votes
1 answer

HealthKit fetch data between interval

I have a little problem grasping HealthKit. I want to get heart rate from HealthKit with specific time. I have done this in the past (until I noticed that I couldn't fetch data when the phone was locked) func…
troligtvis
  • 133
  • 2
  • 8
2
votes
1 answer

Get an array of Blood Glucose records from HealthKit

I'm following some tutorials on HealthKit using swift, one of the tutorials I'm following is how to retrieve some data from the HealthKit such as weight, height age. The tutorial shows how to retrieve the most recent record for each them, the…
Husain Alhamali
  • 823
  • 4
  • 17
  • 32
2
votes
1 answer

How to group HKStatistics by hour?

I'm trying to extract step data from HealthKit. I want to create a summary of step data grouped by hour. Currently, I can extract all of the samples of data between a date range provided by NSPredicate with HKSampleQuery. I could also get a sum of…
Andy M
  • 309
  • 2
  • 9
2
votes
1 answer

HKSampleQuery for HKWorkout

I have a problem to query HKWorkout. Below is the code I use to save HKWorkout and HKQuantitySample. func workout(#distance:Double, start: NSTimeInterval, paused:NSTimeInterval, resume:NSTimeInterval, end:NSTimeInterval, calory:Double) -> HKWorkout…
Ryan
  • 4,799
  • 1
  • 29
  • 56
1
vote
0 answers

iOS how to fix "HKSampleQuery Error reactivating query - Query already exists"?

I'm pulling data from iOS HealthKit in a multi-threaded fashion. I have about 1000 queries prepared for various sample types (3 years of data in 1 day increments). There may be overlapping requests for data between different app components. The code…
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
1
vote
3 answers

How to query for samples from health kit that have an HKDevice

I want to query samples from HealthKit but in order to prevent inaccurate or manipulated data I don't want samples that were written to health by other apps. Does anyone have any idea what predicate I can use to filter out data from all apps or to…
Myk
  • 979
  • 6
  • 16
1
vote
1 answer

Get most recent data point from HKSampleQuery

I am having trouble getting the latest datapoint for weight using an HKSampleQuery. I have the app permissions set correctly, but HKQuantityTypeIdentifier.bodyMass is not returning the most recent data entry from the Health app. How am I supposed…
arodebaugh
  • 538
  • 1
  • 8
  • 26
1
vote
0 answers

Retrieving the value of a variable outside of the scope of an HKSampleQuery

I'm retrieving sleepAnalysis data from HealthKit and want to store these samples in a global array but once I'm outside the scope of the HKSampleQuery, self.globalVariable goes back to it's initial value of an empty array. How can I retrieve these…
1
vote
1 answer

Trouble Retrieving Heart Rate Data from HealthKit

I currently have two records of heart rate earlier this year in January stored in my Health App. In the current app I'm making, I give access to read and write heart rate data. In my viewDidAppear for one of my view controller's, I'm attempting to…
Faisal Syed
  • 921
  • 1
  • 11
  • 25
1
vote
1 answer

How to get HKWorkout's device name tracked by Apple Watch

I am trying to get HKWorkout samples by HKSampleQuery in Apple's HealthKit. By the way I can't get HKWorkout's device name which was tracked by Apple Watch. I could get several HKWorkout Sample data and confirm the sourceRevision and totalDistance…
vcvcvcvc
  • 137
  • 4
  • 10
1
vote
1 answer

How to get cycling duration from HealthKit for ios app using Swift

I am creating an app where I am reading data from health-Kit. I am able to read number of steps, Running + Walking etc. now i am trying to read the date and duration of cycling. This is what I was using for Running + Walking func…
Byte
  • 629
  • 2
  • 11
  • 29
1
vote
1 answer

Statistics for month of HKQuantityType with Cumulative aggregation style

I need to create statistics for month of HKQuantityType with Cumulative aggregation style, like in Health App on year view. HKStatisticsCollectionQuery can calculate only sum for Cumulative types. How it works now. I'm making 12 HKSampleQueries.…
artyom
  • 48
  • 11