2015-10-20 50 views
0

heartRateSample(觀看OS2)我使用獲取日期/時間HKQuantitySample - >從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的日期/時間?

回答

2

量樣品的的startDate和結束日期屬性描述當樣品被採取:

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 
+0

下面是新的NSLog行:的NSLog(@「%@ - HEART RATE:%@ /開始日期:%@/Endate :[自動類],[@([heartRateSample.quantity doubleValueForUnit:heartRateUnit])stringValue],[formatter stringFromDate:heartRateSample.startDate],[formatter stringFromDate:heartRateSample.endDate]); –