gpt4 book ai didi

ios - 如何以秒为单位确定 CMDeviceMotion 的年龄

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:43:53 30 4
gpt4 key购买 nike

我希望能够在游戏期间打开和关闭设备 Action 更新。但是在我将它们关闭然后再次返回后,CMMotionManager 的 .deviceMotion 属性会在短时间内返回最后知道的 deviceMotion(大约 0.5 秒,直到它可以计算出新值,我猜)。

因此,我希望能够测试我获得的 CMDeviceMotion 对象的年龄,如果它们超过几秒则忽略它们。

计算 CACurrentMediaTime() - deviceMotion.timestamp 似乎给我准确的结果。但我担心这可能会在未来的设备或 iOS 版本中中断。设备运动时间戳是否保证在未来与 CACurrentMediaTime() 保持可比性?有没有更好的方法来计算 CMDeviceMotion 时间戳的年龄?

来自 Apple 的文档:

CACurrentMediaTime()

A CFTimeInterval derived by calling mach_absolute_time() and converting the result to seconds.

deviceMotion.timestamp

The time stamp is the amount of time in seconds since the phone booted.

最佳答案

我遇到了同样的问题,需要保留事件的历史记录。我通过将 updateInterval 设置为非常低的值来解决这个问题,例如0.5。因此,Core Motion 不需要重新初始化传感器,并且您可以降低能耗。

关于ios - 如何以秒为单位确定 CMDeviceMotion 的年龄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15837517/

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