如何在IOS中获取加速度计数据? [英] How to get accelerometer data in IOS?

查看:36
本文介绍了如何在IOS中获取加速度计数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UIAccelerotmeterDelegate 方法 accelerometer:didAccelerate: 但最近该方法在 iOS 5.0 中已被弃用.那么获取加速度计数据的替代方法是什么?文档没有提到我们应该使用的替代方案.

I am using the UIAccelerotmeterDelegate method accelerometer:didAccelerate: but recently that method has been deprecated in iOS 5.0. So what is the alternative way to get the accelerometer data? The documentation does not mention the alternative we are supposed to use.

推荐答案

你应该使用 Core Motion 框架(在 iOS 4.0 中引入)作为替代.创建一个 CMMotionManager 实例并告诉它startAccelerometerUpdatesToQueue:withHandler:,传递给它一个 NSOperationQueue 和一个将在指定队列上执行的块只要有新的加速度计数据可用.

You should use the Core Motion framework (introduced in iOS 4.0) as a substitue. Create an instance of CMMotionManager and tell it to startAccelerometerUpdatesToQueue:withHandler:, passing it an NSOperationQueue and a block that will be executed on the specified queue whenever new accelerometer data is available.

这篇关于如何在IOS中获取加速度计数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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