
[2017-04-11 20:16:34 +0000] CMpedometerData,startDate 2017-04-11 20:16:32 +0000 endDate 2017-04-11 20:18:41 +0000 steps 3 distance 2.130000000004657 floorsAscended (null) floorsDescended (null) currentPace (null) currentCadence (null) averageActivePace 0>
正如你可以看到我的客户端(我不能重现这个错误)得到pedometerData从方法startpedometerUpdatesFromDate和endDate 2017-04-11 20:18:41比现在更大2017-04-11 20:16:34(它是第一个CMpedometerData之后startpedometerUpdatesFromDate在从后台返回后启动 – willEnterForeground方法).也许有人已经遇到类似的问题?
我的代码部分:
- (voID)dIDEnterBackground { dispatch_async(dispatch_get_main_queue(),^{ [[pedometer sharedInstance].motionActivityManager stopActivityUpdates]; [[pedometer sharedInstance].pedometer stoppedometerUpdates]; });}- (voID)willEnterForeground { NSDate *NowDate = [NSDate new]; /* here is request to get historical data from lastDateUpdate (store in database) to Now date */ [[pedometer sharedInstance] importDataFrom:lastDateUpdate endDate:NowDate completion:^{ dispatch_async(dispatch_get_main_queue(),^{ /* show info */ }); }]; dispatch_async(dispatch_get_main_queue(),^{ [self startUpdatingData:NowDate]; }); lastDateUpdate = NowDate;}- (voID)startUpdatingData:(NSDate *)fromDate { NSOperationQueue *activityQueue = [[NSOperationQueue alloc] init]; [[pedometer sharedInstance].motionActivityManager startActivityUpdatesToQueue:activityQueue withHandler:^(CMMotionActivity * _Nullable act) { ... }]; [[pedometer sharedInstance].pedometer startpedometerUpdatesFromDate:fromDate withHandler:^(CMpedometerData * _Nullable pedometerData1,NSError * _Nullable error) { ... NSLog(@"%@",pedometerData1); ... lastDateUpdate = pedometerData1.endDate; ... }];}解决方法 我不认为这可以避免,因为这取决于太多的外部因素. 您可以做的是使用逻辑来过滤/排列数据,因为您知道收到的“现在”日期的任何数据实际上将在此之前,因此如果您只对步骤感兴趣或类似的事情,那么只需获得计数.
如果你真的对准确的时间和步骤感兴趣,那么我可以想到3个选择:
1)考虑时间偏移数据被破坏.
2)使用外部源(服务器)而不是设备时间的时间.
3)通过使用内部时钟进行复杂的时间管理:Is there a clock in iOS that can be used that cannot be changed by the user
总结以上是内存溢出为你收集整理的ios – CMPedometerData中的endDate不正确全部内容,希望文章能够帮你解决ios – CMPedometerData中的endDate不正确所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)