Skip to content

Instantly share code, notes, and snippets.

@abhibeckert
Created July 2, 2013 08:57
Show Gist options
  • Save abhibeckert/5907754 to your computer and use it in GitHub Desktop.
Save abhibeckert/5907754 to your computer and use it in GitHub Desktop.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self update];
self.backgroundTaskIdentifier =
[application beginBackgroundTaskWithExpirationHandler:^(void) {
@autoreleasepool {
NSLog(@"begin in background after 10 minutes");
[motionManager stopAccelerometerUpdates];
motionManager.accelerometerUpdateInterval = 0.2f;
[self update2];
[self endBackgroundTask];
}
}];
}
-(void)update2
{
[motionManager startAccelerometerUpdates];
NSLog(@"begin back acc");
while (1) {
@autoreleasepool {
//app enter foreground
if ([[UIApplication sharedApplication] backgroundTimeRemaining] > 600.0f) {
break;
}
////this make no use for dat.
// CMAccelerometerData *dat = motionManager.accelerometerData;
// CMAcceleration acceleration=dat.acceleration;
// [dat release];
CMAcceleration acceleration = motionManager.accelerometerData.acceleration;
NSLog(@"update2: x:%f y:%f z:%f",acceleration.x,acceleration.y,acceleration.z);
sleep(0.2);
}
}
NSLog(@"%s stoped acc",__func__);
[motionManager stopAccelerometerUpdates];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment