toggling proximity sensor on iPhone loses an event

Posted by slugolicious on Stack Overflow See other posts from Stack Overflow or by slugolicious
Published on 2009-03-11T16:54:43Z Indexed on 2010/03/21 9:41 UTC
Read the original article Hit count: 485

Filed under:
|
|
|

I'm using setProximitySensingEnabled and implemented proximityStateChanged in my UIApplication subclass. It looks like if sensing is toggled, that the first "off" event is being lost.

My UIApplication class is pretty basic...

  -(void)proximityStateChanged:(BOOL)state { NSLog(state ? @"ON" : @"OFF"); }

In my application delegate, I have a UISwitch that enables/disables the proximity sensor.

-(IBAction)toggleProxy:(id)sender { [UIApplication sharedApplication].proximitySensingEnabled = prox.on; }

"prox" is my UISwitch. The test works fine when it first starts. I tap the switch to turn it on and then put my hand over the sensor for a second then move it away and get:

2009-03-11 12:43:00.465 Proximity[324:20b] ON
2009-03-11 12:43:02.514 Proximity[324:20b] OFF
2009-03-11 12:43:04.046 Proximity[324:20b] ON
2009-03-11 12:43:05.621 Proximity[324:20b] OFF

I then tap the switch to turn it off then tap again to turn it on. Now I get:

2009-03-11 12:43:12.005 Proximity[324:20b] ON
2009-03-11 12:43:14.789 Proximity[324:20b] ON
2009-03-11 12:43:16.467 Proximity[324:20b] OFF
2009-03-11 12:43:17.516 Proximity[324:20b] ON
2009-03-11 12:43:19.077 Proximity[324:20b] OFF

Notice I get two ON's before an OFF. The OFF is lost somewhere. I can't replicate this behavior using Google's mobile app so I'm wondering if they're resetting something in between proximity enabling. They don't have the proximity sensor on all the time because if you cover the sensor, the screen doesn't go blank. You have to tilt the phone up and angle it back (to simulate the position it would be in at your ear) and then covering the sensor works.

Anyone else playing with the sensor?

In my particular app, I'm recording a voice message and when you move the phone away from your ear, I want to pause the recording (when I get an OFF). The first time I move the phone away from my ear, the recording is not paused. However, if I put it to my ear and move it away again, it is paused.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about api