views:

1091

answers:

4
+5  Q: 

Turning screen off

Hi,

I need my application to be running without the iPhone going to sleep. But I'd like to turn the screen off. Something similar is done in the Phone application, when you speak on the phone.

I prevent the iPhone from going to sleep in the following way: [ [UIApplication sharedApplication] setIdleTimerDisabled: YES];

But how can I turn the screen off? And how do I turn it back, when user touched the screen?

Thanks.

A: 

I can't confirm that that's a public functionality, but I know that there is a proximity sensor which can sense whether the phone is near your face or not. Try digging in and figuring out if that sensor is publicly available, and then which function might be turning the screen off.

TahoeWolverine
A: 

There is no official (public) programmatic way to turn the screen on or off, or even to change the brightness of the display. A few apps "fake" a brightness change by super-imposing a transparent black view on top of your view and changing its opacity to give the appearance of a change in brightness (the back-light will remain on, though, so it will never look like the screen is off and you won't save any battery).

Wilson
+3  A: 

Update: This method has been deprecated. See the comment by Timothée Boucher below.


You can turn the screen off via the proximity sensor, but there is no other public way to put the screen to sleep.

-[UIApplication setProximitySensingEnabled:(BOOL)]
James Skidmore
For anybody reading this, at the time of my comment, the method has been deprecated. From Apple's documentation: "Deprecated. The properties `proximityMonitoringEnabled` and `proximityState` of the `UIDevice` class are the replacements."
Timothée Boucher
A: 

ya thair is the way you can use undocumented function GSEventSetBacklightFactor(1); this will make screen dim. if you replace 1 with 0 your screen will be off. then you have to press home button.for using this u have to import a priate framework graphicservice framework

Nirmit Patel
It cannot be turn on with "GSEventSetBacklightFactor(1);" on a device with 3.1.2 framework. Even home button does not help, but only restarting device (Home+Sleep 10 seconds). It works on a the simulator. The device is uncracked.
slatvick
@slatvick - You mean `not jailbroken`, not `uncracked`. I hope it's not cracked.
Moshe