Chapter 14. Working with Devices
In this chapter, we demonstrate the use of the several devices available on the iPhone. Section 14.1 discusses the usage of the accelerometer. In Section 14.2, you learn how to play short and long audio files, how to record audio files, and how to utilize the iPod library. Next, Section 14.3 shows how to play video files. After that, Section 14.4 shows how to obtain iPhone/iPod touch device information. Using the camera and the photo library is described in Section 14.5. After that, Section 14.6 shows you how to obtain state information regarding the battery of the device. Next, we discuss the proximity sensor in Section 14.7. Finally, we summarize the chapter in Section 14.8.
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 gs, where g is the acceleration due to gravity on earth at sea-level (1g is equal to 9.80 m s−2).
Basic accelerometer values
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 ...
Get iPhone SDK 3 Programming: Advanced Mobile Development 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.