简体   繁体   English

关闭iPhone OS(iOS)中的显示

[英]Turn off display in iPhone OS (iOS)

is there a way to programmatically turn off the display in iOS? 有没有办法以编程方式关闭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. 我很乐意使用私有API,因为这是供个人使用。

Thanks! 谢谢!

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;

You can do this, (obviously, using Private APIs of course) : 你可以这样做(显然,使用私有API):

on iOS5: 在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: 在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 eg a proximity event occurs while in a call. 这是系统在例如呼叫期间发生接近事件时使用的内容。

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 您可以查看-[UIApplication setProximitySensingEnabled:(BOOL)]-[UIApplication setIdleTimerDisabled:YES] ,这可能会导致一些有用的东西

Have you tried: 你有没有尝试过:

[[UIScreen mainScreen] setBrightness: yourvalue];

SO question 8936999: iPhone: How can we programmatically change the brightness of the screen? 问题8936999: iPhone:我们如何以编程方式更改屏幕亮度?

Proximity doesn't work on all devices. 接近不适用于所有设备。 There's a much simpler solution to this problem without resorting to private APIs. 没有诉诸私有API,这个问题有一个更简单的解决方案。

Swift 迅速

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

Without wantsSoftwareDimming , the backlight will never completely turn off. 没有wantsSoftwareDimming ,背光将永远不会完全关闭。 The docs have this cautionary sentence: 文档有这个警示句:

The default value is false. 默认值为false。 Enabling it may cause a loss in performance. 启用它可能会导致性能下降。

I do not think there is any to turn off the display (simulating iphone sleep button) except changing the brightness. 除了改变亮度之外,我认为没有关闭显示器(模拟iphone睡眠按钮)。

This link might help. 链接可能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM