hksamplequery

Get an array of Blood Glucose records from HealthKit

[亡魂溺海] 提交于 2020-01-23 12:54:11
问题 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 following codes shows that: func readMostRecentSample(sampleType:HKSampleType , completion: ((HKSample!, NSError!) -> Void)!) { // 1. Build the Predicate let past = NSDate.distantPast() as! NSDate let now = NSDate() let mostRecentPredicate = HKQuery

How to get Apple health data by date wise?

杀马特。学长 韩版系。学妹 提交于 2020-01-03 07:24:09
问题 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 = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyWasUserEntered, operatorType: .notEqualTo, value: true) let timeSortDesriptor = NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false)//as in health kit entry let quantityType =

Get most recent data point from HKSampleQuery

大憨熊 提交于 2019-12-20 05:23:23
问题 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 to grab the latest datapoint for body mass using an HKSampleQuery ? The reason I think this is because the 0.0 I set for Weight is what is returning and I am getting no console output on readWeight Edit 1 My code including the debugging process is

HealthKit cannot read steps data

妖精的绣舞 提交于 2019-12-11 13:07:22
问题 I'm working with HealthKit to read steps data from my iOS device. here is my code: if ([HKHealthStore isHealthDataAvailable]) { __block double stepsCount = 0.0; self.healthStore = [[HKHealthStore alloc] init]; NSSet *stepsType =[NSSet setWithObject:[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]]; [self.healthStore requestAuthorizationToShareTypes:nil readTypes:stepsType completion:^(BOOL success, NSError * _Nullable error) { if (success) { HKSampleType *sampleType

Getting yesterdays steps from HealthKit

只愿长相守 提交于 2019-12-10 14:23:46
问题 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 function from inside a view, and then appends that to a variable from that same view. I have scoured most of the healthKit questions, and I get back data, but I don't think it is accurate data. My phone data from yesterday is 1442 steps, but it's

How to get walking and running distance using HealthKit in swift

限于喜欢 提交于 2019-12-10 10:24:42
问题 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 type = HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning) let date = NSDate() let cal = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! let newDate = cal.startOfDayForDate(date) let predicate = HKQuery

Get an array of Blood Glucose records from HealthKit

北城以北 提交于 2019-12-06 09:04:27
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 following codes shows that: func readMostRecentSample(sampleType:HKSampleType , completion: ((HKSample!, NSError!) -> Void)!) { // 1. Build the Predicate let past = NSDate.distantPast() as! NSDate let now = NSDate() let mostRecentPredicate = HKQuery.predicateForSamplesWithStartDate(past, endDate:now, options: .None) // 2. Build the sort descriptor to

Get most recent data point from HKSampleQuery

吃可爱长大的小学妹 提交于 2019-12-02 04:02:40
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 to grab the latest datapoint for body mass using an HKSampleQuery ? The reason I think this is because the 0.0 I set for Weight is what is returning and I am getting no console output on readWeight Edit 1 My code including the debugging process is as follows. public func readWeight(result: @escaping (Double) -> Void) { if (debug){print("Weight")} let

Better way to run multiple HealthKit sample queries?

大憨熊 提交于 2019-12-01 22:50:10
问题 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 to be run one, then in the HKSampleQuery's resultsHandler call the second, then in that resultsHandler call the third. That feels kind of -- I don't know -- it feels like I'm missing something. Is there a better way or is the naive approach

Get total step count for every date in HealthKit

你。 提交于 2019-11-27 08:08:45
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 HKQuantitySamples per day. - (instancetype)initWithSampleType:(HKSampleType *)sampleType predicate:(NSPredicate *)predicate limit:(NSUInteger)limit sortDescriptors:(NSArray *)sortDescriptors resultsHandler:(void (^)(HKSampleQuery *query, NSArray *results, NSError *error))resultsHandler I guess I can query all recorded step counts and go through the