Chapter 10. Using Sensors

Mobile phones aren’t just for making phone calls anymore. The iPhone, like a lot of high-end smartphones these days, comes with a number of sensors: camera, accelerometer, GPS module, and digital compass. We’re entering a period of change: more and more users expect these sensors to be integrated into the “application experience.” If your application can make use of them, it probably should.

Hardware Support

While the iPhone is almost unique among mobile platforms in guaranteeing that your code will run on all of the current devices, there is some variation in available hardware between the various models.

Determining Available Hardware Support

Table 10-1 lists the hardware differences between the devices. Because your app will likely support multiple devices, you’ll need to write code to check which features are supported and adjust your application’s behavior as appropriate.

Table 10-1. Hardware support in various iPhone and iPod touch models

Hardware features

Original iPhone

iPhone 3G

iPhone 3GS

First- generation iPod touch

Second- generation iPod touch

Third- generation iPod touch

Cellular

x

x

x

   

WiFi

x

x

x

x

x

x

Bluetooth

x

x

x

 

x

x

Speaker

x

x

x

 

x

x

Audio-in

x

x

x

 

x

x

Accelerometer

x

x

x

x

x

x

Magnetometer

  

x

   

GPS

 

x

x

   

Proximity sensor

x

x

x

   

Camera

x

x

x

   

Video capture

  

x

   

Vibration

x

x

x

   

Network availability

We covered Apple’s Reachability code in detail in Apple’s ...

Get Learning iPhone Programming 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.