views:

502

answers:

3

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.

A: 

Take a look at this thread

John Fricker
Already did a week or so ago. It doesn't address my issue.
slugolicious
A: 

Hi,

I am facing the same, did you manage to figure it out?

Thanks!

yuli
A: 

Hi John,

Thanks for your answer. I looked at this before but it doesn't deal with the problem in question.

To make my question clearer, I get proximityStateChanged notification where state is NO although the device is still covered. Moreover, the screen background-light is still off which means Apple understands the device is near my ear but reports otherwise. Any other suggestions?

Thanks!

yuli