Heim > Fragen und Antworten > Hauptteil
在调用CoreMation框架获取计步数据的时候, 我想获取某一段时间内 每天的计步数的情况。我获取到的数据 和 健康APP中的数据不一样,请问我这个地方是不是设置的时间不对?我应该怎么设置呢?
下面是我的代码和 输出日志:
//加载最新数据
- ( void)loadLastestDatas
{
for (int i = 1; i < 10; i++)
{
NSString *dateStr = [NSString stringWithFormat:@"2016-09-0%zd", i];
NSDate *fromDate = [NSDate date];
fromDate = [DateUtil stringToDate:dateStr dateFormat:@"yyyy-MM-dd"];
NSLog(@"from:%@", fromDate);
[self addStepsDataWithDate:fromDate];
}
[self endRefresh];
[self.tableView reloadData];
}
- (void)addStepsDataWithDate:(NSDate *)fromDate
{
WS(ws);
[self.pedometer queryPedometerDataFromDate:fromDate
toDate:[NSDate dateWithTimeInterval:24*60*60 sinceDate:fromDate]//后一天
withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
if (pedometerData == nil) {
return;
}
NSString *str = [NSString stringWithFormat:@"共走了%@步", pedometerData.numberOfSteps];
[ws.datas addObject:str];
}];
}];
}
2016-09-10 10:40:00.344 GYBase[4342:2163762] from:2016-09-01 00:00:00 +0000
2016-09-10 10:40:00.353 GYBase[4342:2163762] from:2016-09-02 00:00:00 +0000
2016-09-10 10:40:00.355 GYBase[4342:2163762] from:2016-09-03 00:00:00 +0000
2016-09-10 10:40:00.357 GYBase[4342:2163762] from:2016-09-04 00:00:00 +0000
2016-09-10 10:40:00.359 GYBase[4342:2163762] from:2016-09-05 00:00:00 +0000
2016-09-10 10:40:00.361 GYBase[4342:2163762] from:2016-09-06 00:00:00 +0000
2016-09-10 10:40:00.362 GYBase[4342:2163762] from:2016-09-07 00:00:00 +0000
2016-09-10 10:40:00.364 GYBase[4342:2163762] from:2016-09-08 00:00:00 +0000
2016-09-10 10:40:00.366 GYBase[4342:2163762] from:2016-09-09 00:00:00 +0000
2016-09-10 10:40:00.377 GYBase[4342:2163762] 共走了0步
2016-09-10 10:40:00.379 GYBase[4342:2163762] 共走了8618步
2016-09-10 10:40:00.380 GYBase[4342:2163762] 共走了8574步
2016-09-10 10:40:00.380 GYBase[4342:2163762] 共走了9596步
2016-09-10 10:40:00.381 GYBase[4342:2163762] 共走了7418步
2016-09-10 10:40:00.382 GYBase[4342:2163762] 共走了7213步
2016-09-10 10:40:00.382 GYBase[4342:2163762] 共走了7821步
2016-09-10 10:40:00.383 GYBase[4342:2163762] 共走了7389步
2016-09-10 10:40:00.383 GYBase[4342:2163762] 共走了7461步
请输入代码
下面是我健康APP中的数据