Chapter 13. Working with Devices

In this chapter, we demonstrate the use of the several devices available on the iPhone. Section 13.1 discusses the usage of the accelerometer. In Section 13.2, we show how to play small sound files. Next, Section 13.3 shows how to play video files. After that, Section 13.4 shows how to obtain iPhone/iPod touch device information. Using the camera and the photo library is described in Section 13.5. Finally, we summarize the chapter in Section 13.6

Working with the Accelerometer

The iPhone is equipped with an easy-to-use accelerometer. The accelerometer provides you with the current orientation of the device in 3D space. You subscribe to these updates with a given frequency (10 updates/s to 100 updates/s) and you receive three floating-point values in each update. These values represent the acceleration of x, y, and z in space. The acceleration on each axis is measured in g s, where g is the acceleration due to gravity on earth at sea-level (1g is equal to 9.80 m s−2).

If you hold the iPhone in front of you and imagine an axis that goes through the Home button and the earpiece that is orthogonal to the floor, then that axis is the y-axis. Positive values of y indicate that the phone is accelerating up and negative values indicate that it is accelerating down towards the floor. The x-axis goes from right to left perpendicular to the y-axis. Positive values indicate that the force is towards your right side and negative values indicate that the force is ...

Get iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.