3

The docs related to proximity sensing state that if the proximity sensing APIs are used on a device without a proximity sensor (i.e. iPod touch, iPad) they will just return as if the proximity sensor has fired.

Aside from checking the [[UIDevice currentDevice].model] string and parsing for "iPhone", "iPod touch", or "iPad" is there a slicker way to determine if a proximity sensor is on a given device?

3 Answers 3

4

Taken from UIDevice documentation:

proximityMonitoringEnabled

A Boolean value indicating whether proximity monitoring is enabled (YES) or not (NO).

...

Discussion

....

Not all iPhone OS devices have proximity sensors. To determine if proximity monitoring is available, attempt to enable it. If the value of the proximityState property remains NO, proximity monitoring is not available.

Claus

Sign up to request clarification or add additional context in comments.

Comments

2

Apple’s documentation notes that “Not all iPhone OS devices have proximity sensors.” To determine if the device your app is running supports proximity monitoring, set the proximityMonitoringEnabled property to YES, then check its value:

UIDevice *device = [UIDevice currentDevice]; device.proximityMonitoringEnabled = YES; if (device.proximityMonitoringEnabled == YES) // do something 

Source: http://www.mobileorchard.com/new-in-iphone-30-tutorial-series-part-4-proximity-detection/

2 Comments

The doc says : To determine if proximity monitoring is available, attempt to enable it. If the value of the { proximityState property remains NO, proximity monitoring is not available. But really, I don't understand the point if you enable the proximityState without anything in front of the sensor...
Not directly relevant, but never compare anything to YES. Just evaluate it in a boolean context, like, if (device.proximityMonitoringEnabled)
0

Maybe this snippet could be helpful:

-(BOOL) hasProximitySensor { UIDevice *dev = [UIDevice currentDevice]; BOOL oldValue = [dev isProximityMonitoringEnabled]; [dev setProximityMonitoringEnabled:!oldValue]; BOOL newValue = [dev isProximityMonitoringEnabled]; [dev setProximityMonitoringEnabled:oldValue]; return (oldValue != newValue); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.