gpt4 book ai didi

iOS CoreMotion API——有没有办法跟踪某人在一段时间内走了多少次?

转载 作者:行者123 更新时间:2023-11-29 12:22:49 26 4
gpt4 key购买 nike

我正在尝试编写一个简单的应用程序,让我可以使用 CoreMotion API 跟踪我在设定天数内的平均步行时间。 CMPedometer API 允许访问上次 session 的开始日期和结束日期。我在想,一个简单的方法是在用户默认设置中保留 session 的“统计”(即每次计步器跟踪您的步行时,统计增加 1)并且还保留 endDate - startDate 时间差的总和。然后,我只需将总时间差除以计数即可得到平均步行时间。

我不确定该怎么做。每次计步器跟踪步行时,有没有办法收集这些数据?

最佳答案

CMPedometer API gives access to startDate and endDate of your last session.

哪个 API 可以做到这一点? CMPedometer docs仅指定以下方法:

- 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. Specifying a start date that is more than seven days in the past returns only the available data.

我想你在找CMMotionActivityManager .根据文档,从 CMMotionActivityManager 获取事件非常简单:

- queryActivityStartingFromDate:toDate:toQueue:withHandler:

该查询将为您提供一组 CMMotionActivity 对象。按“walking = YES”过滤,您将获得指定时间段内的步行训练列表(仅适用于过去 7 天)。

我不能说它有多准确,也不能说您是否需要自己进行一些数据清理/过滤。

关于iOS CoreMotion API——有没有办法跟踪某人在一段时间内走了多少次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30111411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com