【问题标题】:Get date/time for HKQuantitySample -> heartRateSample (Watch OS2) from HealthKit从 HealthKit 获取 HKQuantitySample -> heartRateSample (Watch OS2) 的日期/时间
【发布时间】:2015-10-20 19:01:39
【问题描述】:

我正在使用

-(void)updateHeartRate:(NSArray<__kindof HKSample *> *)samples

从内部手表传感器检索 HearteRate。根据应用在后台(停用)的时间,必须使用以下方法检索几个 heartRateSamples:

if (samples.count>0) {

    for (HKQuantitySample *heartRateSample in samples) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (heartRateSample) {
            NSLog(@"HEART RATE: %@", [@([heartRateSample.quantity doubleValueForUnit:heartRateUnit]) stringValue]);
            }
        });
    }
}

但是如何检索特定样本写入 HealthKit 的日期/时间?

【问题讨论】:

    标签: watchkit watchos-2 healthkit


    【解决方案1】:

    数量样本的 startDate 和 endDate 属性描述了采样的时间:

    HK_CLASS_AVAILABLE_IOS(8_0)
    @interface HKSample : HKObject
    
    @property (readonly, strong) HKSampleType *sampleType;
    
    @property (readonly, strong) NSDate *startDate;
    @property (readonly, strong) NSDate *endDate;
    
    @end
    

    【讨论】:

    • 这是新的 NSLog 行: NSLog(@"%@ - HEART RATE: %@ / Startdate: %@ / Endate: %@", [self class], [@([heartRateSample.数量 doubleValueForUnit:heartRateUnit]) stringValue], [formatter stringFromDate:heartRateSample.startDate], [formatter stringFromDate:heartRateSample.endDate]);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-21
    相关资源
    最近更新 更多