1 Reply
      Latest reply on Aug 12, 2015 11:30 AM by stacconi
      dev0400 Level 2 Level 2 (25 points)

        I'm attempting to tell the Apple Watch to update the heart rate. Any ideas on how to force update? I'd like it to update every x amount of time.

        Below is my query.

         

        HKQuantityType *heartRateQuantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate];
           
           
            NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate ascending:NO];
           
            HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:heartRateQuantityType predicate:nil limit:1 sortDescriptors:@[timeSortDescriptor] resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error) {
                if (!results) {
                    NSLog(@"An error occured fetching the user's tracked food. In your app, try to handle this gracefully. The error was: %@.", error);
                   
                    /
                   
                }
        

         

        All help is much appreciated, as the current docs don't seem to cover this.

        • Re: Update Heart Rate
          stacconi Level 1 Level 1 (10 points)

          There's no way to tell HealthKit to update the HR every x amount of time.  The best thing you can do is to start a workout session (HKWorkoutSession) on the watch by calling startWorkoutSession.  Once you do this you'll get HR updates every 5 seconds or so.