I started working on an existing app and noticed that the time "fast-forwards" when the app has been in the background for a long time. I shut it down at (example) 09:30 minutes, when I open it at 14:21 it did all of the work but only then it starts updating the UI. In a few seconds, it races through all of the data from five minutes in background.
This is not acceptable behavior for my app, so this is what I have done:
- Added background mode (location) to my capabilities
Of course I linked CoreMotion to use the gyro/accelerometer.
self.motionManager = [[CMMotionManager alloc] init]; //Gyroscope if([self.motionManager isGyroAvailable]) { // Start the gyroscope if it is not active already if([self.motionManager isGyroActive] == NO) { // Update us 2 times a second // [self.motionManager setGyroUpdateInterval:1.0f / 1.0f]; [_motionManager setAccelerometerUpdateInterval:0.1]; [self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) { if(error){ NSLog(@"%@", error); } else { //NSString *x = [[NSString alloc] initWithFormat:@"%.02f",accelerometerData.acceleration.x]; float g = 9.80665f; float AccelX = accelerometerData.acceleration.x * g; float Accely = accelerometerData.acceleration.y * g; float Accelz = accelerometerData.acceleration.z * g; [self getSicknessIndicator:AccelX ay:Accely az:Accelz]; } }]; //Receive the gyroscope data on this block } }
I'm not quite sure why this behavior happens and I also tried out a lot of other questions on StackOverflow but with no result, unfortunately. They mostly tell me to add the background mode.