CMMotionActivityManager - 在应用程序暂停或在后台运行时接收动作活动更新 [英] CMMotionActivityManager - Receiving motion activity updates while app is suspended or in background

查看:142
本文介绍了CMMotionActivityManager - 在应用程序暂停或在后台运行时接收动作活动更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在测试新的Motion Activity Manager API( CMMotionActivityManager )。我想创建一个应用程序,可以在应用程序未在前台运行时从 startActivityUpdatesToQueue 接收和处理动作更新。我正确接收运动更新(静止,行走,跑步,汽车,未知),同时应用程序位于前台,但一旦进入后台(因此被暂停),应用程序就会停止运动更新。 / p>

CMMotionActivityManager Class参考
此方法异步启动运动数据的跟踪。在调用此方法时,运动活动管理器在指定的队列上执行处理程序块,报告对设备有效的当前运动。即,运动活动管理器仅在运动数据发生变化时才执行处理程序块。
处理程序块在尽力而为的基础上执行,并且在您的应用程序暂停时不会发送更新。如果在您的应用程序被暂停时到达更新,最后一次更新会在恢复时发送给您的应用执行。要获取暂停应用程序时发生的所有更新,请使用 queryActivityStartingFromDate:toDate:toQueue:withHandler: method。



我想要一种方法让我的应用程序在后台运行并接收动态数据(实时)。现在,保持应用程序在后台运行的唯一方法是使用后台服务,但动态更新不在允许的后台服务列表中:



App Store评论指南:多任务应用程序可能只将背景服务用于其预期目的:VoIP,音频播放,位置,任务完成,本地通知等。
我不想拥有位置更新(GPS)始终(为了节省电池)。如果我保持连续的位置更新,但关闭GPS,应用程序将被暂停。



请让我知道如何让我的应用程序在后台运行并接收mot离子活动更新。
必须有一种方法可以做到这一点:我尝试了Strava应用....即使应用程序在后台,当用户暂停运行时它会关闭GPS。当用户恢复运行时,它会自动打开GPS(所有这一切都在应用程序处于后台)...这可能意味着应用程序在后台运行并且即使在GPS关闭时也会主动接收动作活动更新。



提前谢谢!

解决方案

这不是新的问题。从未有过Core Motion后台使用设置。如果您的应用程序在后台运行,则允许您使用Core Motion,但要使其在后台运行,您必须执行其他操作(例如,在用户将应用程序发送到后台时获取位置更新,以及您在Info.plist中列出位置后台服务。



请注意,在iOS 7中,如果您有正确的硬件,您可以使用延迟的位置更新来定期在后台唤醒您的应用程序。这样您可以节省电力,但您的应用程序可以在后台运行,然后没有Info.plist后台服务列表。


I've been testing the new Motion Activity Manager APIs (CMMotionActivityManager). I want to create an app that can receive and process motion updates from startActivityUpdatesToQueue while the app is not running in the foreground. I correctly receive motion updates (stationary, walking, running, automotive, unknown) while the app is in the foreground but as soon as it goes into the background (and thus gets suspended), motion updates cease to be received by the app.

CMMotionActivityManager Class Reference: "This method initiates the tracking of motion data asynchronously. Upon calling this method, the motion activity manager executes the handler block on the specified queue, reporting the current motion in effect for the device. After that, the motion activity manager executes the handler block only when the motion data changes. The handler block is executed on a best effort basis and updates are not delivered while your app is suspended. If updates arrived while your app was suspended, the last update is delivered to your app when it resumes execution. To get all of the updates that occurred while your app was suspended, use the queryActivityStartingFromDate:toDate:toQueue:withHandler: method."

I want a way to keep my app running in the background and receive motion data (real-time). Right now the only way to keep the app running in the background is to use background services but "motion updates" is not in the list of allowed background services:

App Store Review Guidelines: "Multitasking Apps may only use background services for their intended purposes: VoIP, audio playback, location, task completion, local notifications, etc." I don't want to have Location Updates (GPS) on all the time (to save battery). If I bank on continuous location updates but switch the GPS off, the app will get suspended.

Please let me know how to keep my app running in the background and receive motion activity updates. There must be a way to do it: I tried the Strava app....even when the app is in the background, it swithes the GPS off when the user pauses running. When the user resumes running, it automatically turns the GPS on (all this while the app is in the background)...this probably means that the app is running in the background and actively receiving motion activity updates even while the GPS is off.

Thank you in advance!

解决方案

This is not a new issue. There has never been a Core Motion background usage setting. You are allowed to use Core Motion if your app is running in the background, but to make it run in the background you have to be doing something else (e.g. getting location updates at the time the user sends the app into the background, and you have the location background service listed in your Info.plist.

Note too that in iOS 7 if you have the right hardware you may be able to use deferred location updates to wake your app periodically in the background. Thus you save power but your app gets to run in the background now and then without an Info.plist background service listing.

这篇关于CMMotionActivityManager - 在应用程序暂停或在后台运行时接收动作活动更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆