Operations in background

107 views Asked by At

I was doing some research about reading accelerometer data while app is in background and I found that there is no pure solution for the problem. You can use some callback from other api-s like playing audio, recording audio, receiving location updates ... etc. However I found an interesting thing.

When I start the function below and I tap to home button the app goes to background but the "running" message keeps writing out itself to the log.

- (void)updateAccelerometer {
    while (YES) {
        NSLog(@"running");
    }
}

The other interesting thing is that I turned of the Background Modes.

My question is that... Can I use this infinite loop approach for reading the CMMotionManager's accelerometer data while the app is in background? It looks like a solution. Did somebody use it? Do someone know other approach for reading the CMMotionManager data in background?

Any kind of idea link could be helpful. If you have a thought, please share with me. Thanks for your time.

1

There are 1 answers

1
coneybeare On BEST ANSWER

This won't work past the default time provided for all apps to finish work in the background. If you try it on a device, you will see that it probably stops after around 60 seconds. Not only that, but it is horrible for the processor to do this kind of loop and will considerably slow down the machine, especially if on the main thread. There used to be apps which were marketed as hand warmers that would do exactly this, if you get what I mean.