核心运动在后台?

发布于 2024-10-16 04:29:13 字数 38 浏览 2 评论 0原文

当应用程序在后台运行时,Core Motion 框架会工作吗?

Will Core Motion framework work while the app is in the background?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

乱世争霸 2024-10-23 04:29:13

Core Motion 框架允许访问 CMPedometer 数据的历史数据,因此如果您的应用程序仅使用此框架,则无需在后台运行。

上周我一直在玩 CM,在我的测试中,如果您的应用程序发送到后台时正在运行活动查询,则查询处理程序在返回到时会收到大量事件(在应用程序暂停时发生)前景。我不知道将缓存多少事件,并且我没有在文档中看到任何有关此的内容。

这种行为似乎已经足够了。我想不出 Core Motion 的用例,您需要持续的后台访问,历史 CMPedometer 数据还不够,并且符合 App Store 指南。

The Core Motion framework allows access to historical data for CMPedometer data, so if your app is only using this there is no need to run in the background.

I have been playing around with CM the last week and in my testing if you have an active query running when your app is sent to the background, the query handler receives a flood of events (that occurred while the app was suspended) upon returning to the foreground. I don't know how many events will be cached, and I haven't seen anything in the docs about this.

This behaviour seems to be sufficient. I can't think of a use case for Core Motion where you need constant background access, historical CMPedometer data doesn't suffice, and fits within the App Store guidelines.

旧话新听 2024-10-23 04:29:13

取决于您对工作的定义...核心动画需要继续运行还是您希望视图被冻结?当应用程序在后台运行时,仅允许某些进程运行。 (例如通知)。

在大多数情况下,应用程序 UI 都会暂停,直到您触发 applicationDidBecomeActive。一旦再次启动,它应该恢复,但不会继续在后台运行。对于运行 OpenGL 的 iOS 上的大多数游戏来说也是如此,它会暂停,直到应用程序再次激活。

Depends on your definition of working... Will Core Animation need to continue running or are you expecting the view to be frozen? When an app runs in the background only certain processes are allowed to run. (Notifications for example).

For the most part the application UI, and by extension is paused until you trigger applicationDidBecomeActive. Once that starts up again it should resume, but again not continue running in the background. Same can be said for most games on iOS running OpenGL, it's paused until the app is active again.

遮云壑 2024-10-23 04:29:13

其中一款用于跟踪您行走步数的应用程序“moves”非常令人惊奇,因为即使您将其置于后台或被杀死,它也可以指示您走过的步数。因此,当应用程序被杀死时,陀螺仪和 GPS 以及其他传感器的某些内部机制可以继续运行。

one of the apps- moves that is used to track your walking steps is quite amazing, because even you make it into background or killed, it can indicate the steps you walked. So some internal mechanism of gyroscope and GPS and other sensors can carry on when the apps are killed.

不忘初心 2024-10-23 04:29:13

为了让您的应用程序在后台运行,您必须将其声明为后台任务。问题是只有几个 UIBackgroundModes ...而运动不是其中之一。

解决方法可能是启用 UIBackgroundMode location,其目的是让用户知道他们的位置,即使应用程序位于后台也是如此。然后您可以将运动逻辑包含在其中。然而,这样做的明显缺点是它涉及 GPS 的使用,这会显着耗尽电池......

In order to let your app run in the background, you have to declare it as a background task. The problem is that there are only a few UIBackgroundModes ... and motion isn't one of it.

A workaround could be to enable the UIBackgroundMode location, which is intended to let users know about their location even if the app is in the background. You could then wrap your motion logic within. Nevertheless, the clear drawback of this is that it involves usage of the GPS, which will drain the battery significantly...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文