The iPhone contains several sensors. These include an accelerometer, gyroscope, magnetometer, pedometer, and barometer. Each of these are open and available for you to use in your app. The tutorials below show you how to connect up to each sensor to retrieve the data you want.
CMMotionManager and Accelerometer – The CMMotionManager is used to access sensors. In this tutorial we show you how to connect up to the accelerometer to receive raw data from the sensors.
CMMotionManager and Gyroscope – The CMMotionManager is also used to connect up to the gyroscope in the phone. This tutorial shows you how to retrieve data from the gyroscope.
CMMotionManager and Magnetometer – Like the two tutorials above, the magnetometer is also accessed via the CMMotionManager. This tutorial shows you how to connect up the magnetometer.
CMMotionManager and Device Motion Data – This tutorial looks at CMDeviceMotion. This particular class gathers data from all sensors on the device and fuses them together to create readings with bias removed. In this post we draw a needle on the screen that faces down regardless of the angle you rotate your phone around the Z axis.
How to use the CMPedometer for Counting Steps – Apple has provided us with the CMPedometer class that is responsible for providing step counts. As well as being able to provide updates of your step count for today, CMPedometer also keeps track of the previous 7 days worth of step count data. This is kept regardless of your app wanting to use that data or not. This tutorial will teach you how to access live step data as well as historical step data.
How to Use the CMMotionActivityManager – The CMMotionActivityManager class provides you with motion data. That motion data is a log of when the iPhone sensed you were stationary, walking, running, cycling, or in a moving vehicle. In a similar way to how 7 days worth of pedometer data is kept, the iPhone also keeps 7 days of motion data of which you can query with a start and end date to receive a log of what you were doing. As well as being able to provide historical data, your app can also request live updates.
How to Access the iPhone Barometer with CMAltimeter – The iPhone has a barometer inside that can be used to detect pressure changes and give you your elevation changes from the point you started the service. In this tutorial we create a CMAltimeter object so that we can receive that information and place the results on the screen as they change.