TurtleKurtze TurtleKurtze - 2 years ago 165
iOS Question

iPhone screen sleep - built in proximity sensor

Bon jour

is it possible to implement the following:

a. user places the iphone screen side down.
b. the screen sleeps (black)
c. the app reamins in foreground with full functionality

I believe other apps might achieve this with the proximity sensor?

Will this drain the battery significantly?


Answer Source

You can do:

[UIDevice currentDevice].proximityMonitoringEnabled = YES;
BOOL shouldDimScreen = [UIDevice currentDevice].proximityState;

if (shouldDimScreen) {
    // do whatever you want
} else {
    // light the screen back up

You can use NSNotificationCenter to register for the UIDeviceProximityStateDidChangeNotification if you'd like to know every time the status changes.

But, iOS will automatically turn off the screen for you if the user doesn't touch it for a while. So as long as you don't turn off the idle timer your battery life will be fine, and you might not need to implement this.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download