Created
July 2, 2013 08:57
-
-
Save abhibeckert/5907754 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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