Tag: hksamplequery

HealthKit无法读取步骤数据

我正在使用HealthKit从我的iOS设备读取步骤数据。 这里是我的代码: 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 = [HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; HKSampleQuery *sampleQuery = [[HKSampleQuery alloc] initWithSampleType:sampleType predicate:nil limit:HKObjectQueryNoLimit sortDescriptors:nil resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error) { […]

从HealthKit获取昨天的步骤

我正在构build一个个人使用的应用程序,而且我目前正在坚持如何准确地从healthkit得到昨天的步骤。 然后从那里,把它放到一个variables(应该很容易,我知道)。 我有一个HealthKitManager类,从视图内调用该函数,然后将其附加到来自同一视图的variables。 我已经search了大部分健康问题的资料,并且找回数据,但是我不认为这是准确的数据。 我昨天的电话数据是1442步,但是它返回了2665步。 最重要的是,当我试图把数据是一个variables,打印出0。 HealthKitManagerClass import Foundation import HealthKit class HealthKitManager { let storage = HKHealthStore() init() { checkAuthorization() } func checkAuthorization() -> Bool { // Default to assuming that we're authorized var isEnabled = true // Do we have access to HealthKit on this device? if HKHealthStore.isHealthDataAvailable() { // We have to […]

从HealthKit获取一系列血糖logging

我正在使用swift关于HealthKit的一些教程,我正在遵循的教程之一是如何从HealthKit中检索一些数据,如体重,身高的年龄。 本教程将演示如何检索每个logging的最新logging,以下代码显示: 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 return the samples in descending order let sortDescriptor = NSSortDescriptor(key:HKSampleSortIdentifierStartDate, ascending: false) // 3. we […]