Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Accelerometer data in background using core motion? [duplicate]

The new Nike+ GPS application for iOS 5 is able to process accelerometer events in the background (thus allowing for indoor treadmill tracking). How is this possible? When I put my application in background, it ceases receiving events. I use the standard UIAccelerometer API.

like image 895
kyrpoff Avatar asked Jan 03 '12 17:01

kyrpoff


People also ask

How do you get the accelerometer data on Apple Watch?

No. Direct access to the Apple Watch sensors (which include the accelerometer) is not possible. As always, if this is something you'd like, please file a request for it at https://bugreport.apple.com. Show activity on this post.


1 Answers

For the sake of providing an answer to this question, even though it is already self answered...

"If you use the newer Core Motion API, you can receive updates in the background."

Here is an example:

- (void)startAccelerationCollection {
    [self.motionManager startAccelerometerUpdatesToQueue:[[NSOperationQueue alloc] init]
                                             withHandler:^(CMAccelerometerData *data, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.accelerometerReadings addObject:data];
        });
    }];
}
like image 70
2 revs, 2 users 62%user1804599 Avatar answered Oct 10 '22 23:10

2 revs, 2 users 62%user1804599