从 HealthKit 获取 HKQuantitySample -> heartRateSample (Watch OS2) date/time
Get date/time for HKQuantitySample -> heartRateSample (Watch OS2) from HealthKit
我正在使用
-(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 时,我如何检索 date/time?
数量样本的开始日期和结束日期属性描述了样本的采集时间:
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
我正在使用
-(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 时,我如何检索 date/time?
数量样本的开始日期和结束日期属性描述了样本的采集时间:
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