21.0. Introduction

iOS devices are usually equipped with accelerometer hardware. Some iOS devices might also include a gyroscope, such as the new iPhone and the new iPad. Before attempting to use either the accelerometer or the gyroscope in your iOS applications, you must check the availability of these sensors on the iOS device on which your app runs. Recipes 21.1 and 21.2 include techniques you can use to detect the availability of the accelerometer and gyroscope. With a gyroscope, iOS devices are able to detect motion in six axes.

Let’s go through a situation that will show you 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 in some iOS devices 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 also whether it is changing in relation to the Earth along these directions, ...

Get iOS 7 Programming Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.