views:

17520

answers:

14

Can the iPhone SDK take advantage of the iPhone's proximity sensors? If so, why hasn't anyone taken advantage of them? I could picture a few decent uses.

For example, in a racing game, you could put your finger on the proximity sensor to go instead of taking up screen real-estate with your thumb. Of course though, if this was your only option, then iPod touch users wouldn't be able to use the application.

Does the proximity sensor tell how close you are, or just that something is in front of it?

+2  A: 

There is no public API for this.

Chris Lundie
A: 

Those proximity sensors are basically a matrix of conductors. The vertical "wires" are tracks on one side of a thin sheet of insulator, the horizontal ones are on the other side. The intersections function as capacitors. Your finger carries an electrostatic charge, so capacitance of each junction varies with proximity. FETs amplify the signal and biasing sets a threshold. In practice the circuit is more complex than that because it has to detect a relative change and reject noise.

But anyway, what the sensor grid tells you is that a field effect has been sensed, and that field effect is characteristic of object about the size of a fingertip and resting on the surface of the display. The centroid of the capacitive disturbance is computed (probably by hardware) and the coordinates are (presumably) reported as numbers on a port most likely brought to the attention of the device OS by an interrupt. In something as sexy as an iPhone there's probably a buffer of the last dozen or so positions so it can work out direction and speed. Probably these are also computed by hardware and presented as numbers on the same port.

Peter Wone
It sounds like you are describing the touch screen, not the proximity sensor (which shuts off the screen when you hold the phone to your ear). As far as I can tell, that's just a light sensor.
benzado
I am, a touch screen *is* a proximity sensor. I didn't realise there was an ear-detection mechanism.
Peter Wone
+8  A: 

Assuming you mean the sensor that shuts off the screen when you hold it to your ear, I'm pretty sure that is just an infrared sensor inside the ear speaker. If you start the phone app (you don't have to be making a call) and hold something to cast a shadow over the ear speaker, you can make the display shut off.

When you asked this question it was not accessible via the public API. You can now access the sensor's state via UIDevice's proximityState property. However, it wouldn't be that useful for games, since it is only an on/off thing, not a near/far measure. Plus, it's only available on the iPhone and not the iPod touch.

benzado
The iPod touch actually does have a light sensor. I can see it on mine near the top-left corner, above the screen, in direct sunlight. The screen brightness can auto-adjust to ambient lighting conditions.
Chris Lundie
Uh... I didn't say the iPod doesn't have an ambient light sensor. We were discussing the proximity sensor, which as far as I can tell is implemented by detecting light.
benzado
Oh so in the iPhone it's 2 different sensors?
Chris Lundie
if it was a light sensor then the display would go off during a call in a dark room?
Dipak Patel
This is technically untrue. There is a light sensor to automatically adjust screen brightness and a second infrared LED / sensor pair to detect the proximity of your face. (Holding a white sheet of paper an inch or two above the speaker end of the phone will trigger the proximity sensor, yet the display still works in a dark room.)
Brendan Berg
I updated my answer to take your comments into account.
benzado
A: 

Looks like Google is using it but it's not, as benzado pointed out, in the SDK. Go figure.

Coderer
+19  A: 

There is a public API for this. -[UIApplication setProximitySensingEnabled:(BOOL)] will turn the feature on. BTW, it doesn't seem to be using the light sensor, because proximity sensing would tweak out in a dark room.

However, the API call basically blanks the screen when you hold the phone up to your face. Not useful for interaction, sadly.

Brendan Berg
Robert Gould
How is this not the correct answer?
willc2
The UIApplication method is deprecated. In 3.0 you enable it with:[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];Also, it is possible to check the property proximityState, so if you poll that value, it could be a primitive input method.
Jason Moore
There was no public API at the time this question was asked; I've updated my answer (the accepted one) to reflect the change.
benzado
Actually, no need to poll the value of proximityState. Just observe the notification: UIDeviceProximityStateDidChangeNotification
Jason Moore
+3  A: 

@Dipak Patel & @Coderer

You can download working code at http://spazout.com/google_cheats_independent_iphone_developers_screwed

It has a working implementation of proximityStateChanged a undocumented method in UIApplication.

Hope this helps.

chews
A: 

This is not how the prox sensor works. It's not strictly light-based, as I just tested turning out the lights in a room, and the sensor didn't trip. However, I could make it trip by holding my hand over it about 5-6 inches away. Your description is accurate about how the touch screen works, but the prox sensor works without having to contact it (or even be that near). A friend suggested something ultrasonic. Anyone know for sure?

+5  A: 

The proximity sensor works via measuring IR reflectance. If you hold the iPhone up to a webcam, you can see a small, pulsing IR LED.

A: 

Interesting possiblities. Would it be possible to register the pulsing ledlight in your home-energymeter using the proximity meter? Some of these lights only send out an IR-signal Does it work in standby-mode as well?

+2  A: 

In iPhone 3.0 there is official support for the proximity sensor. Have a look at UIDevice proximityMonitoringEnabled in the docs.

Zaph0d42
+2  A: 

Evidently the proximity sensor will never turn on if the status bar is in landscape orientation.

i.e. if you call:

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;

You will no longer get proximity:ON notifications.

This definitely happens on OS 3.0, I can't test it on a 2.X device since I don't have one with a proximity sensor.

This seems like a bug.

Kevin Lambert
A: 

What does heat have to do with activating the sensor. In hot weather, after I've been holding the phone next to my face to talk, the "end call" button doesn't work! It's as if athe whole screen has been warmed up so that it does not detect the heat of my finger( that I use to touch that button). After about a minute away from my face, the end call button will respond. Same is true for "accept call" and "decline call " ???

I'd guess it's more likely that perspiration on the screen is screwing with touch detection.
Brendan Berg
+1  A: 

There's a lot of confusion between the proximity sensor and the ambient light sensor. The iPhone has both. The Touch does not have a proximity sensor, making it a poor choice for user input. It would be a bad idea anyway since Apple isn't obligated to locate it in the same place in future devices; you aren't supposed to know or care where it is.

The proximity sensor works by pulsing an infrared LED and measuring the amount of reflectance. You can see this using your iSight camera (most digital cameras are sensitive to IR.) Just launch Photo Booth, initiate a call (or play a voicemail) on the phone and point it at your iSight camera. Note the flashing light next to the earpiece; cover it with your finger and the screen will go black.

The ambient light sensor's API is evidently private at this point.

Cryptognome
I would disagree with the proximity sensor being IR based. I can cover the top of the phone with a solid object, like a note pad, and the sensor is not triggered. However, I can touch the top of the phone with my chin and the sensor is triggered. I tested this with the call dialing app.
Brenden
The experiment I suggested, which makes the IR transmitter clearly visible, should remove any doubt. It is only active when proximity sensing is enabled, such as on a call or playing a voicemail. I don't know why your notepad failed to trigger it, but it worked for me using a greeting card, notepad and a paper towel.
Cryptognome
A: 

To turn the screen off it's conceivable that more than one sensors is used to figure out if the screen should be turned off or not. The IR proximity sensor described by Cryptognome in conjunction with the Touch screen sensor described by Peter Wone could work out if the iphone is being held close to your face (or something else with a slight electric charge) or if its just very close to something in-animate.