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

Unique among modern mobile platforms, Apple has gone to great lengths to ensure that your code will run on all of the current iOS-based devices. Yet despite this, there is still some variation in hardware between the various models (see Table 9-1).

Table 9-1. Hardware support in various iPhone, iPod touch, and iPad models

Hardware feature

iPhone

iPod touch

iPad

iPad 2

Original

3G

3GS

4

4S

1st Gen

2nd Gen

3rd Gen

4th Gen

WiFi

3G

WiFi

3G

Cellular

WiFi

Bluetooth

Speaker

Audio In

Accelerometer

Magnetometer

Gyroscope

GPS

Proximity Sensor

Camera

Video

Vibration

Retina Display

Network Availability

We covered Apple’s Reachability code in detail in Apple’s Reachability Class in Chapter 7. We can easily determine whether the network is reachable, and whether we are using the wireless or WWAN interface:

Reachability *reach = [Reachability reachabilityForInternetConnection]; NetworkStatus status = [reach currentReachabilityStatus]; ...

Get Learning iOS Programming, 2nd Edition 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.