Receive Accelerometer Updates in Background Using Coremotion Framework

Receive accelerometer updates in background using CoreMotion framework

You can not only use accelerometer for fetching data from background,

And as you say your App registers for location updates , start location manager in the foreground.

Implementing Long-Running Background Tasks

For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:

  1. Apps that play audible content to the user while in the background, such as a music player app
  2. Apps that record audio content while in the background.
  3. Apps that keep users informed of their location at all times, such as a navigation app
  4. Apps that support Voice over Internet Protocol (VoIP)
  5. Apps that need to download and process new content regularly
  6. Apps that receive regular updates from external accessories

Continuous accelerometer updates while in the background on iOS

Considering this was asked 3 years ago, I'm going to try and give a response applicable to 2017. If you are using Swift I would strongly suggest using this framework https://github.com/MHaroonBaig/MotionKit.

It makes it very trivial to use CoreMotion services. There is probably another friendly wrapper for Core Location services.

I found another SO question that seems to have answered this using your approach of hijacking location services to stay active in the background.

Run app for more than 10 minutes in background

Hopefully this helps. I'll just leave a word of caution that using location services to get continuous accelerometer data in the background without actually needing the location services would probably be grounds to have your app rejected from the app store. Navigation apps genuinely use both location and accelerometer data. The simple answer would be to add a feature that actually uses the location to justify getting the accelerometer data in the background. Anyway, best of luck.

Location and accelerometer updates in the background under iOS 10

Beginning with iOS 9, there is a new call required to enable background processing of location events. It can be used to turn background processing on and off, but defaults to off, so it must be set manually to restore background processing in iOS 8 and prior code.

Add this line when setting up the location manager to allow background processing:

    locationManager.allowsBackgroundLocationUpdates = YES;

iPhone collecting CoreMotion data in the background. (longer than 10 mins)

Use this one:

Apps that keep users informed of their location at all times, such as a navigation app

In other words, you make a location manager and tell it to start doing updates. You don't have to do anything with those updates! But as long as this is happening - that is, as long as your app is continuing to do location updates in the background - your app is also allowed to use Core Motion in the background. This is not just a trick; it is official Apple policy as explained in one of the WWDC videos from a couple of years ago.

Using the accelerometer of an iOS device in background

Your problem has been issued in several threads all over stackoverflow.
Next time you should really use the search function or at least post some code.

In the meantime check this:
From this thread Receive accelerometer updates in background:

You can not only use accelerometer for fatching data from background,

And as you say your App registers for location updates , start
location manager in forground.

Implementing Long-Running Background Tasks For tasks that require more
execution time to implement, you must request specific permissions to
run them in the background without their being suspended. In iOS, only
specific app types are allowed to run in the background:

Apps that play audible content to the user while in the background,
such as a music player app Apps that record audio content while in the
background. Apps that keep users informed of their location at all
times, such as a navigation app Apps that support Voice over Internet
Protocol (VoIP) Apps that need to download and process new content
regularly Apps that receive regular updates from external accessories

Short Version: It is not possible to ONLY get acceleration data in background.



Related Topics



Leave a reply



Submit