I have researched this topic thoroughly before asking the question but need to ensure that I have come to the right conclusions and, if so, I would like help on implementing this as efficiently as possible.
It is essential for my app to receive accelerometer updates every 5 seconds or so and may be more quickly under certain situations; without this feature, its not a very useful app.
So, how to go about achieving this? The basic strategy is to use the method:
[cmMotionManager startDeviceMotionUpdatesToQueue:...]
with an appropriate deviceMotionUpdateInterval
and then to somehow 'make sure' your application never gets suspended ie. you have to implement one of the background modes (e.g. Location, Background Audio, VOIP etc)
This is the strategy used by many applications already on the app store such as Sleep Cycle ("sound recording"), Nike+ and Pacer (sound playback).
(Correct me if there is another way to continuously get accelerometer information)
My problem is that my app won't be recording sound, doesn't need VOIP etc and doesn't require any of the new background fetch/remote notification API in iOS 7. So how to go about making sure I stay active in the background?
Well, since im designing an app that measures movement, its not a far stretch to receive Location information. My question is how to go about implementing location updates in the most efficient way possible given the fact that I don't really need these location updates at all while ensuring that my app is never suspended?
This is what I have at the moment in my app delegate:
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
- (void)applicationWillResignActive:(UIApplication *)application
{
[self.locationManager startUpdatingLocation];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[self.locationManager stopUpdatingLocation];
}
I have noticed that sometimes for a short while after the time I press the home button on my app, my app becomes suspended - presumably as Core Location tries to get a location fix to deliver to the app.
I would also like to know, once you have been awoken by a location update, how long do you have before the system suspends you again if a new location update doesnt arrive? Will I have to try and receive continuous location updates (navigation style) to ensure I am never suspended?
Please help!
Thanks