Turn off display in iPhone OS (iOS)

徘徊边缘 提交于 2019-11-26 09:08:07

问题


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!


回答1:


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;



回答2:


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.




回答3:


The only way I know of, public or private, is using the power button.

You might look at -[UIApplication setProximitySensingEnabled:(BOOL)], or -[UIApplication setIdleTimerDisabled:YES], this might lead to something useful




回答4:


Have you tried:

[[UIScreen mainScreen] setBrightness: yourvalue];

SO question 8936999: iPhone: How can we programmatically change the brightness of the screen?




回答5:


Proximity doesn't work on all devices. There's a much simpler solution to this problem without resorting to private APIs.

Swift

UIScreen.main.wantsSoftwareDimming = true
UIScreen.main.brightness = 0.0

Without wantsSoftwareDimming, the backlight will never completely turn off. The docs have this cautionary sentence:

The default value is false. Enabling it may cause a loss in performance.




回答6:


I do not think there is any to turn off the display (simulating iphone sleep button) except changing the brightness.

This link might help.



来源:https://stackoverflow.com/questions/3950194/turn-off-display-in-iphone-os-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!