Chapter 15. Core Motion
iOS devices such as the iPhone and iPad are usually equipped with accelerometer hardware. Starting with the iPhone 4, some iOS devices might also include a gyroscope. Before attempting to use either the accelerometer or the gyroscope in your iOS applications, you must check the availability of these devices on the iPhone or iPad. Recipe 15.1 and Recipe 15.2 include techniques you can use to detect the availability of the accelerometer and gyroscope. With a gyroscope, iOS devices such as the iPhone 4 are able to detect motion in six axes.
Let’s set up a simple example you can try out to see the value of the gyroscope. The accelerometer cannot detect the rotation of the device around its vertical axis if you are holding the device perfectly still in your hands, sitting in a computer chair, and rotating your chair in a clockwise or counterclockwise fashion. From the standpoint of the floor or the Earth, the device is rotating around the vertical axis, but it’s not rotating around its own y-axis, which is the vertical center of the device. So, the accelerometer does not detect any motion.
However, the gyroscope included with iOS devices starting with the iPhone 4 allows us to detect such movements. This allows more fluid and flawless movement detection routines. This is typically useful in games, where the developers need to know not only whether the device is moving on the x-, y-, and z-axes—information they can get from the accelerometer—but ...