How to get accelerometer data in IOS?

前端 未结 6 2054
被撕碎了的回忆
被撕碎了的回忆 2021-02-08 09:58

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

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-08 10:10

    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.

提交回复
热议问题