I'm using the following code to get accelerometer data (using CoreMotion
framework):
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
motionManager.accelerometerUpdateInterval = 1.0 / 60.0;
[motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
NSLog(@"ACCELEROMETER DATA = %@",accelerometerData);
}];
When the app is in foreground mode, I'm receiving the log, but when it enters background, I receive the log only when the music in the app is playing.
I've added the following to app info plist file:
- Required background modes
- App registers for location updates
- App plays audio or streams audio/video using AirPlay
The question is: how can I receive accelerometer updates in background, when the music is not playing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…