gpt4 book ai didi

accelerometer - 在 watchOS 2 中关闭屏幕时无法获取加速度计和心率数据

转载 作者:行者123 更新时间:2023-12-02 06:31:39 25 4
gpt4 key购买 nike

我正在使用 CMMotionManager 和 HKWorkoutSession 开发 Apple Watch 应用程序以获取加速度计和心率数据。该应用程序在短时间内(70 秒)运行良好,但当屏幕关闭时,心率和加速度计数据都会停止。

我的问题是如何从加速度计和心率传感器获得 5 分钟的数据?

最佳答案

要在应用程序进入后台时花费更多时间,您可以使用 performExpiringActivityWithReason 。这在这里描述 https://developer.apple.com/videos/play/wwdc2015/228/?time=345 在我的 watch 上它只需要大约 30 秒

NSProcessInfo.processInfo().performExpiringActivityWithReason("Reason") {
expired in
if !expired {
let delay: Int64 = 30
let delayTime = dispatch_time(DISPATCH_TIME_NOW, delay * Int64(NSEC_PER_SEC))
dispatch_semaphore_wait(semaphore, delayTime)
} else {
dispatch_semaphore_signal(semaphore)
}
}

关于accelerometer - 在 watchOS 2 中关闭屏幕时无法获取加速度计和心率数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34407740/

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