O'Reilly logo

iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch by Maher Ali

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required