23

The release of IOS5 has this core function listed as deprecated. Does anyone know what will replace it? I'm assuming that apple is not going to remove the accelerometer from iPhone 5.

1 Answer 1

29

I did not yet use iOS 5, but already in 4.x UIAccelerometer and UIAccelerometerDelegate were replaced by the CoreMotion framework. It is more sophisticated, takes gyroscope signals into account and performs a sensor fusion i.e. does calibrating stuff like bias calculation for you.

Basically the CMDeviceMotionHandler block callback is now the equivalent. It is called every deviceMotionUpdateInterval seconds or you can go with your own timer loop and pull the data. It is pretty straightforward and easy to use. Look at Simple iPhone motion detect and follow the three links to the SDK docs.

There are three things you have to bear in mind:

  • Working with Device Motion requires iPhone version >= 4 or newest iPod touch generation because it relies on gyroscope support
  • When using Device Motion you must not use low pass filtering to extract gravity because it is done for you
  • If you want to support older hardware, you have to work with raw data. This is done by creating a CMAccelerometerHandler and calling startAccelerometerUpdatesToQueue:withHandler:. Then you have to extract gravity with low pass filtering like in didAccelerate
3
  • So, do you know what replaces accelerometer:didAccelerate: ? My application uses it, but I would like to support the application in iOS5 when it is released. Thanks Commented Jul 21, 2011 at 7:18
  • 1
    @jcpennypincher: See updated answer and follow the 3 links provided in the referenced answer (Simple iPhone...).
    – Kay
    Commented Jul 21, 2011 at 11:01
  • 1
    At the time that Kay wrote this answer, the "newest iPod touch" was the iPod Touch 4. According to Apple, these are the base models with Gyroscope capability: iPhone 4, iPad 2, and iPod Touch 4. From my research, if you are on iOS 7 or above, then you are definitely on a device that has gyro capability. iOS 6 was supported by iPhone 3GS, so I believe that anything iOS 6 or below you'd have to test for gyro capability.
    – henryaz
    Commented Sep 29, 2014 at 16:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.