Chapter 17. Accessing the Hardware


  • How to obtain accelerometer data from your iPhone or iPod Touch

  • How to detect shakes to your device

  • How to obtain geographical data using the Core Location service in the iPhone and iPod Touch

  • How to display a map in your application

In the previous chapter, you saw how you could access the built-in applications on an iPhone and iPod Touch through various means — URL strings as well as using the specialized classes provided by the iPhone SDK. In this chapter, you learn how to access the hardware of your device, such as the accelerometer, and obtain location information through GPS, cell towers, and wireless hotspots.


One of the most innovative features of the iPhone and iPod Touch is the built-in accelerometer. The accelerometer allows the device to detect the orientation of the device and adapts the content to suit the new orientation. For example, when you rotate your device sideways, the Safari Web browser automatically switches the screen to landscape mode so that you now have a wider viewing space. Similarly, the camera relies on the accelerometer to tell it whether you are taking a picture in portrait or landscape mode.

The accelerometer in iPhone and iPod Touch measures the acceleration of the device relative to freefall. A value of 1 indicates that the device is experiencing 1 g of force exerting on it (1 g of force being the gravitational pull of the earth, which your device experiences ...

Get Beginning iPhone® SDK Programming with Objective-C® 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.