Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMMotionActivityManager - Receiving motion activity updates while app is suspended or in background

Tags:

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:

"2.5.4 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.

like image 912
user2853019 Avatar asked Oct 07 '13 02:10

user2853019


1 Answers

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.

like image 147
matt Avatar answered Sep 30 '22 15:09

matt