How Nike+ GPS on iPhone receives accelerometer updates in the background?

后端 未结 2 903
轻奢々
轻奢々 2020-11-28 03:49

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

2条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 04:05

    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];
            });
        }];
    }
    

提交回复
热议问题