Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off display in iPhone OS (iOS)

Tags:

is there a way to programmatically turn off the display in iOS? Not just turning brightness down, but off like the way the Phone App does. I am happy to use private API, since this is for personal use.

Thanks!

like image 717
nitsky Avatar asked Oct 16 '10 18:10

nitsky


2 Answers

You can turn off the display by enabling the proximity monitoring. It will automatically turn off the screen, like in the Phone app, by placing the phone near your ears or by placing a finger over the IR sensor at the top of the phone.

[UIDevice currentDevice].proximityMonitoringEnabled = YES;
like image 65
iMathieuB Avatar answered Sep 23 '22 05:09

iMathieuB


You can do this, (obviously, using Private APIs of course) :

on iOS5:

#include <stdio.h>
#include <dlfcn.h>

int (*SBSSpringBoardServerPort)() = (int (*)())dlsym(RTLD_DEFAULT, "SBSSpringBoardServerPort");
int port = SBSSpringBoardServerPort(); 
void (*SBDimScreen)(int _port,BOOL shouldDim) = (void (*)(int _port,BOOL shouldDim))dlsym(RTLD_DEFAULT, "SBDimScreen");

and then use

SBDimScreen(port,YES); 

whenever you want to dim, and

SBDimScreen(port,NO);

whenever you want to undim.

On iOS6:

void (*BKSDisplayServicesSetScreenBlanked)(BOOL blanked) = (void (*)(BOOL blanked))dlsym(RTLD_DEFAULT, "BKSDisplayServicesSetScreenBlanked");

and then use:

BKSDisplayServicesSetScreenBlanked(1); // 1 to dim, 0 to undim

"Dim" here means totally turn off the screen. This is what the system uses when e.g. a proximity event occurs while in a call.

like image 36
Elias Limneos Avatar answered Sep 23 '22 05:09

Elias Limneos