Heart Rate With Apple's Healthkit

前端 未结 2 465
一向
一向 2021-01-22 14:17

I\'m currently using Healthkit in an app and have no problems getting info for most types, but am having trouble with the Heart Rate. Every time I try to read a sample, I get \

相关标签:
2条回答
  • 2021-01-22 14:48

    if you want to get averageQuantity ask for it in your HKStatisticsQuery options. otherwise it will always be nil (ie. not calculated): options parameter should be set to HKStatisticsOptionDiscreteAverage, NOT HKStatisticsOptionNone

    0 讨论(0)
  • 2021-01-22 15:12

    From what I read and if I'm correct, you are trying to read the heart rate from the beginning of the day up till now.

    Check your start date and end date by logging them out after using a date formatter. Could be possible that the start time and the end time are the same, that is why you get 0 as the result.

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"];
    NSString *dateString = [dateFormatter stringFromDate:beginOfDay];
    NSLog(@"%@", dateString);
    

    You should also set the hour minute and second to zero to ensure that you are getting a time of the start of the day.

    NSDateComponents *components = [calendar components:NSCalendarUnitYear| NSCalendarUnitMonth | NSCalendarUnitDay
                                               fromDate:now];
    components.hour = 0;
    components.minute = 0;
    components.second = 0;
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题