ios5 - iPhone 上的 Nike+ GPS 如何在后台接收加速度计更新?

标签 ios5 accelerometer background-process

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

最佳答案

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

“如果您使用较新的 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];
        });
    }];
}

关于ios5 - iPhone 上的 Nike+ GPS 如何在后台接收加速度计更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13220686/

相关文章:

ios - iOS 应用程序通常如何与服务器通信?

jquery - iOS Web 应用程序 GO 键盘按钮不提交 Ajax 表单

android - 无法解析摇动事件监听器中的 getApplicationContext 和 startActivity 方法 : Android Studio

ios - 当您的应用程序休眠时,您如何知道任务是否在后台执行?

windows - 暂停在 console2 中运行的 bash 中的进程

iphone - 调用addChildViewController后是否还必须调用addSubview?

ios5 - 如何在 iOS 5 中执行与用户输入无关的转场?

iphone - 在 iPhone 中使用加速度计查找距离

android - 跟踪位置室内(使用智能手机)

python - 将 Python 脚本作为 Windows 后台进程运行