Needs
I want to turn the screen off when the user places his iphone upside down on q desk. At the same time I do not want to have the proximity monitor enabled all the time as this is very uncomfortable for the user and miss fires a lot of times depending on how you grab the device.
What for
This is to leave at night and save battery and screen life while still running the app.
The workaround
I am thinking of is to use the accelerometer to determin if the face is down, if so activate the proximity censor. Simple stuff...
The problem
In practice the workaround does not work, It seams that if the censor is "occluded" when you activate it, it will not register its current state.
Refresh UIDevice some how?
What I'm Using
-(id)init {
if ((self = [super init]))
{
NSLog(@"Init ShakerAnalizer");
accelerometer = [UIAccelerometer sharedAccelerometer];
accelerometer.delegate = self;
accelerometer.updateInterval = 5.0f;
}
return self;
}
-(void)accelerometer:(UIAccelerometer *)accel didAccelerate:(UIAcceleration *)acceleration
{
if (accelerometer)
{
NSLog(@"Accelerometer Z::: %f", acceleration.z);
if (acceleration.z > kFlippedThreshold)
device.proximityMonitoringEnabled = YES;
else
device.proximityMonitoringEnabled = NO;
}
}
Using the accelerometer to determin if phone is facing down to activate the proximity censor works well. Using a fast refresh rate to determin when the phone flips is crusial as if you activate the proximity censor when already occluded the screen will stay on. Once the phone is fasing down you can lower the refresh rate to save battery.