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

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

问题描述

适用于iOS 5的新型Nike + GPS应用程序能够在后台处理加速度计事件(因此可以进行室内跑步机跟踪)。这怎么可能?当我将我的应用程序放在后台时,它会停止接收事件。我使用标准的UIAccelerometer API。

解决方案

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



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



<这是一个例子:

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


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...

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

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

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