2

When you hold the iPhone to your ear, it detects that there's something (proximity-sensor) and switches off the display.

is it possible to access this sensor in an iPhone app?

Gareth
  • 133,157
  • 36
  • 148
  • 157
Thanks
  • 40,109
  • 71
  • 208
  • 322
  • I don't think it's a proximity sensor, it just senses light levels. – Paul Tomblin Mar 03 '09 at 15:12
  • It has both a proximity sensor and a light level sensor. It only enables the proximity sensor when it detects that the phone has been moved to the upright position, using the accelerometers. – andynormancx Mar 03 '09 at 15:17

3 Answers3

2

I was able to find this functionality in Apple's documentation here, however I haven't tried it yet.

The UIDevice instance also provides access to the proximity sensor state (described by the proximityState property). The proximity sensor detects whether the user is holding the device close to their face.

kenorb
  • 155,785
  • 88
  • 678
  • 743
AtomicBoolean
  • 1,070
  • 13
  • 19
  • You can check the state using `proximityState` property, but only when `isProximityMonitoringEnabled` is `TRUE` - Unfortunately, neither allows you to prevent the screen from dimming. – JCutting8 Dec 29 '19 at 09:21
2

It is possible via undocumented System calls, this is how Google's voice search works on the iPhone to start listening when it is close to your ear (or so i'm told). The API isn't publicly exposed though so although google got the app on the store your app might be subject to more scrutiny.

Sorry I can't tell you exactly what the calls are.

Quintin Robinson
  • 81,193
  • 14
  • 123
  • 132
  • Does anybody know how to implement the undocumented calls in a Swift Application? Another app seems to have made it into the app store with this functionality: http://www.peekcalendar.com/ – JCutting8 Dec 29 '19 at 09:23
2

I don't think so.

Rather, there aren't any published API's for it.

Google's voice search uses it, but that caused some fuss as they apparently used some unpublished functions.

http://www.iphonehacks.com/2008/11/iphone-app-news.html

EDIT:

To clarify, there are published API's allowing you to turn it on and off, but nothing that will allow you to detect when it has been triggered.

Johan
  • 405
  • 5
  • 14