The Core Motion framework allows your app access to the sensors on the device. The sensors include the accelerometer, gyroscope, and magnetometer. The CMMotionManager class allows access to each of these to get raw data from them so that your app can detect when the device moves. There are a number of applications for this such as sleep tracking, step counting, to name a few. By using a combination of these sensors, your app can calculate information such as your step count.
Creating a step counter could be quite difficult if you were processing raw data and trying to work out the difference between a step and someone just picking up the phone. Thankfully, Apple does the hard work for you by providing you with the CMPedometer class. This class takes this data and provides you with a step count as well as other information such as cadence etc… To make things even better, Apple also provides 7 days worth of history, thanks to the motion coprocessor (introduced in the iPhone 5s). Even if your app isn’t actively running and tracking step counts, the phone is quietly keeping a log of all step counts and statuses and the CMPedometer is the way we retrieve this data. [Read more…]