O'Reilly logo

Beginning iPhone® SDK Programming with Objective-C® by Wei-Meng Lee

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 17. Accessing the Hardware

WHAT YOU WILL LEARN IN THIS CHAPTER

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

USING THE ACCELEROMETER

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

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