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
12
votes
2 answers

How to get Apple health data by date wise?

Apple health app gives the data by Date wise as shown in below image. By using HealthKit i am fetching the steps data from apple health as let p1 = HKQuery.predicateForSamples(withStart: fromDate, end: Date(), options: .strictStartDate) let p2 =…
Jack
  • 13,571
  • 6
  • 76
  • 98
10
votes
6 answers

Get total step count for every date in HealthKit

What's the best way to get a total step count for every day recorded in HealthKit. With HKSampleQuery's method initWithSampleType (see below) I can set a start and end date for the query using NSPredicate, but the method returns an array with many…
MathiasMo
  • 103
  • 1
  • 1
  • 5
6
votes
2 answers

Getting yesterdays steps from HealthKit

I'm building an app for personal use, and I am currently stuck on how to accurately get yesterdays steps from the healthkit. And then from there, placing it into a variable (should be easy, I know). I have a HealthKitManager class that calls the…
impo
  • 747
  • 1
  • 11
  • 37
6
votes
3 answers

Better way to run multiple HealthKit sample queries?

I have a scenario where I need to retrieve multiple sets of data from HealthKit -- body temperature, weight, and blood pressure. I need all 3 before I can continue processing because they're going to end up in a PDF. My naive first approach is going…
Mattio
  • 2,014
  • 3
  • 24
  • 37
5
votes
1 answer

HealthKit Step Counter

I'm trying to use HealthKit's step counter and so far this is what I have. It doesn't fail but I don't see any activity. What am I missing? import UIKit import HealthKit class ViewController: UIViewController { let healthStore: HKHealthStore? =…
Tsundoku
  • 9,104
  • 29
  • 93
  • 127
5
votes
2 answers

How can I get daily average steps form HealthKit

I'm trying to display the daily amount of steps the user takes. But I don't really know how to manage this. I already got this code: let endDate = NSDate() let startDate = NSCalendar.currentCalendar().dateByAddingUnit(.CalendarUnitMonth, value: -1,…
Egghead
  • 6,837
  • 5
  • 20
  • 38
4
votes
4 answers

How to get walking and running distance using HealthKit in swift

I'm making Health App. I want to get walkingRunningDistance from HealthKit in Swift. But, I have a problem. Return value is 0.0mile. Why return value is 0 mile? My code is this. func recentSteps3(completion: (Double, NSError?) -> () ){ let…
Sung-jun Kim
  • 41
  • 1
  • 1
  • 6
4
votes
1 answer

HealthKit Workout Queries seem really slow

I have some code which is querying data from healthkit. We get various samples and quantities from the healthkit as well as recent workouts. On my phone (usually a workout every day - although the Basis stores things as multiple workouts), the…
Fiid
  • 1,852
  • 11
  • 22
4
votes
1 answer

Unit Test HKSampleQuery in Swift

When I need to read data from HealthKit this is how my code looks like: let stepsCount = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount) let stepsSampleQuery = HKSampleQuery(sampleType: stepsCount, predicate: nil, …
Javier Cadiz
  • 12,326
  • 11
  • 55
  • 76
4
votes
1 answer

How to retrieve an array of HealthKit records and their metadata

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
3
votes
0 answers

How to get the distance traveled at a certain location in a HKWorkout

Goal I am currently trying to get the data to plot an elevation chart for a HKWorkout. I want the X-axis to represent distance and the Y-axis to represent elevation. This sort of graph is fairly common and acts as a sort of cross section of a…
bencallis
  • 3,478
  • 4
  • 32
  • 58
3
votes
1 answer

Find HKObject by UUID

In my app users can do workouts and they get listed in my app. If a user wants to delete a workout inside my app, I'd like to offer him to also delete it from HealthKit. But I can't seem to find a way to fetch an HKObject by it's uuid?!? Is that not…
Georg
  • 3,664
  • 3
  • 34
  • 75
3
votes
1 answer

Efficiently parse HKSampleQuery results for HealthKit on iOS

My app uses the HealthKit framework to retrieve user health data. I want to get around 25 different data points from HealthKit. To do this, I currently have the 25 calls in a for-loop inside the completion handler for the sample query. Is there any…
KAREEM MAHAMMED
  • 1,675
  • 14
  • 38
3
votes
1 answer

HKSampleQuery cannot be reused

Create an HKSampleQuery for weight (but don't execute it) Create and execute an HKObserverQuery on weight In the observer query's updateHandler, execute the weight sample query Works fine the first time the sample query is executed. Next time the…
steve1951
  • 193
  • 7
3
votes
1 answer

NSInternalInconsistencyException when running background fetch with a loop

I have this code that is trying to do a background fetch for HealthKit data. The code works fine when I first run the app, but if I manually perform a background fetch (using the debug command), I get an exception thrown and an error that says…
Brandon Shega
  • 769
  • 4
  • 17
1
2 3 4