iPhone 上的 Nike+ GPS 如何在后台接收加速度计更新? [英] How Nike+ GPS on iPhone receives accelerometer updates in the background?

查看:23
本文介绍了iPhone 上的 Nike+ GPS 如何在后台接收加速度计更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

适用于 iOS 5 的新 Nike+ GPS 应用程序能够在后台处理加速度计事件(从而允许室内跑步机跟踪).这怎么可能?当我将应用程序置于后台时,它停止接收事件.我使用标准的 UIAccelerometer API.

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.

推荐答案

为了提供这个问题的答案,即使它已经自我回答...

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

如果您使用较新的 Core Motion API,您可以在后台接收更新."

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

这是一个例子:

- (void)startAccelerationCollection {
    [self.motionManager startAccelerometerUpdatesToQueue:[[NSOperationQueue alloc] init]
                                             withHandler:^(CMAccelerometerData *data, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.accelerometerReadings addObject:data];
        });
    }];
}

这篇关于iPhone 上的 Nike+ GPS 如何在后台接收加速度计更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆