簡體   English   中英

如何獲取分鍾形式的Healthkit中的每日平均步數

[英]How can i get daily average steps in minute form healthkit

這是我的代碼:

HKSampleType *sampleType = [HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];

NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:[[NSDate date] dateByAddingTimeInterval:60*1] endDate:[NSDate date] options:HKQueryOptionStrictStartDate];

如何獲取分鍾形式的保健工具包中的每日平均步數?

- (void)getAvgStepsCount{
   HKHealthStore *healthStore = [[HKHealthStore alloc] init];

   if ([HKHealthStore isHealthDataAvailable]) {
      HKQuantityType *stCountType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
      NSSet *readDataTypes = [NSSet setWithObjects:stCountType, nil];

     [healthStore requestAuthorizationToShareTypes:nil readTypes:readDataTypes completion:^(BOOL success, NSError *error) {
        if (!success) {
            return;
        }
    }];
  }

  HKQuantityType *qType = [HKQuantityType
                        quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount
                        ];

  NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:yesterdayDate endDate:todayDate options:HKQueryOptionStrictStartDate];

  HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:qType
                                                       predicate:predicate
                                                           limit:1
                                                 sortDescriptors:nil
                                                  resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error) {
    if (!results)
        return;

    HKQuantitySample *quantitySample = results.firstObject;
    HKQuantity *quantity = quantitySample.quantity;

    HKUnit *stepsUnit = [HKUnit countUnit];
    double avgStepsInMinute = [quantity doubleValueForUnit:stepsUnit]/24/60;

}];

[healthStore executeQuery:query];}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM