简体   繁体   English

iOS CoreMotion API-是否可以跟踪一段时间内某人走路的次数?

[英]iOS CoreMotion API — Is there a way to keep track of how many times someone goes walking over a period of time?

I'm trying to write a simple app that will allow me to keep track of my average walking time over a set number of days using CoreMotion API. 我正在尝试编写一个简单的应用程序,使我可以使用CoreMotion API在设定的天数内跟踪平均步行时间。 The CMPedometer API gives access to startDate and endDate of your last session. CMPedometer API允许您访问上一个会话的startDate和endDate。 I was thinking that an easy way to do this would be to keep a 'tally' of sessions in user defaults (ie everytime the pedometer tracks your walking the tally increases by 1) and also keeping a sum of endDate - startDate time differences. 我当时想,执行此操作的一种简单方法是在用户默认设置中保持会话的“计数”(即,每次计步器跟踪您的步行计数时,计数都会增加1),并且还要保持endDate与startDate时差之和。 Then, I would just divide the total time Differences by the tally to get an average walking time. 然后,我将总时间差除以计数即可得出平均步行时间。

I'm not sure how I'd do this. 我不确定该怎么做。 Is there a way to collect this data every single time that the pedometer tracks walking? 有没有一种方法可以在计步器每次跟踪步行时收集此数据?

CMPedometer API gives access to startDate and endDate of your last session. CMPedometer API使您可以访问上一个会话的startDate和endDate。

Which API does that? 那是哪个API? The CMPedometer docs only specify the following method: CMPedometer文档仅指定以下方法:

- queryPedometerDataFromDate:toDate:withHandler:

Use this method to retrieve historical pedestrian data between the specified dates. 使用此方法可检索指定日期之间的历史行人数据。 This method runs asynchronously and delivers the data to the block you provide. 该方法异步运行,并将数据传递到您提供的块。 Only the past seven days worth of data is stored and available for you to retrieve. 仅存储了过去7天的数据,可供您检索。 Specifying a start date that is more than seven days in the past returns only the available data. 指定开始日期超过7天只会返回可用数据。

I think you are looking for CMMotionActivityManager . 我认为您正在寻找CMMotionActivityManager According to the docs, getting activities from CMMotionActivityManager is pretty straightforward: 根据文档,从CMMotionActivityManager获取活动非常简单:

- queryActivityStartingFromDate:toDate:toQueue:withHandler:

That query will give you an array of CMMotionActivity objects. 该查询将为您提供CMMotionActivity对象数组。 Filter by "walking = YES" and you've got your list of walking sessions for the specified time period (only works for last 7 days). 按“步行=是”过滤,您将获得指定时间段内的步行会话列表(仅适用于过去7天)。

I cannot say how accurate it is or whether or not you need to do some of your own data scrubbing/filtering. 我不能说它的准确性如何,或者您是否需要做一些自己的数据清理/过滤工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在iOS应用中计算一段时间内的Parse API请求? - How to count Parse API requests over a period of time in an iOS app? 如何在iOS 6中将步行轨迹或路线显示为地图叠加层 - How to display a walking track or route as a Map Overlay in iOS 6 如何跟踪iOS中的音轨进展? - How to keep track of audio track progression in iOS? 如何跟踪cocos2d中的精灵被触摸了多少次? - How can I keep track of how many times a sprite has been touched in cocos2d? CoreMotion-确定是否在iOS设置中禁用运动的方法? - CoreMotion - way to determine if motion is disabled in iOS Settings? 如何在不同时间段内跟踪数据(快速)-计数器/习惯跟踪应用程序 - How to keep track of data over various periods of time (Swift) - Counter/Habit Tracking App 如何在 iOS 的后台跟踪用户步行并使用 Swift 和 Xcode 计算到目前为止行进的距离? - How do I track in the background in iOS a user walking and calculate the distance traveled so far using Swift and Xcode? iOS:如何跟踪用户制作的书签? - iOS: How to keep track of the bookmarks the user makes? 如何本地化时间段(iOS / OSX) - How to localise a time period (iOS/OSX) 即使在“删除”应用程序之后,有没有办法跟踪经过的时间? - Is there a way to keep track of elapsed time even after app is “Deleted”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM