search

Home  >  Q&A  >  body text

Objective-c - The data obtained by the implemented pedometer is inconsistent with the data in the health APP. Solve the problem.

When calling the CoreMation framework to obtain step counting data, I want to obtain the daily step count within a certain period of time. The data I obtained is different from the data in the Health APP. Is the time set in this place wrong? How should I set this up?

Here is my code and output log:

//加载最新数据
- ( 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] Total 0 steps taken
2016-09-10 10:40:00.379 GYBase[4342:2163762] A total of 8618 steps have been taken
2016-09-10 10:40:00.380 GYBase[4342:2163762] A total of 8574 steps have been taken
2016-09-10 10:40:00.380 GYBase[4342:2163762] A total of 9596 steps have been taken
2016-09-10 10:40:00.381 GYBase[4342:2163762] A total of 7418 steps have been taken
2016-09-10 10:40:00.382 GYBase[4342:2163762] A total of 7213 steps have been taken
2016-09-10 10:40:00.382 GYBase[4342:2163762] A total of 7821 steps have been taken
2016-09-10 10:40:00.383 GYBase[4342:2163762] A total of 7389 steps have been taken
2016-09-10 10:40:00.383 GYBase[4342:2163762] A total of 7461 steps have been taken

请输入代码

The following is the data in my health APP

滿天的星座滿天的星座2783 days ago811

reply all(0)I'll reply

No reply
  • Cancelreply