在 iPhone 操作系统 (iOS) 中关闭显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3950194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:55:58  来源:igfitidea点击:

Turn off display in iPhone OS (iOS)

iphoneiosiphone-privateapi

提问by nitsky

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.

有没有办法以编程方式关闭 iOS 中的显示?不仅仅是降低亮度,而是像电话应用程序那样关闭。我很高兴使用私有 API,因为这是供个人使用的。

Thanks!

谢谢!

回答by iMathieuB

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;

回答by Elias Limneos

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 e.g. a proximity event occurs while in a call.

“昏暗”在这里意味着完全关闭屏幕。这是系统在例如通话中发生接近事件时使用的内容。

回答by Adam

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],这可能会导致一些有用的东西

回答by cleverbit

Have you tried:

你有没有尝试过:

[[UIScreen mainScreen] setBrightness: yourvalue];

[[UIScreen mainScreen] setBrightness: yourvalue];

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

SO 问题 8936999:iPhone:我们如何以编程方式更改屏幕亮度?

回答by James H

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

Proximity 不适用于所有设备。这个问题有一个更简单的解决方案,而无需求助于私有 API。

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:

没有wantsSoftwareDimming,背光永远不会完全关闭。文档中有这样的警告语句:

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

默认值为假。启用它可能会导致性能下降。

回答by Chaitanya

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

除了改变亮度之外,我认为没有任何关闭显示器(模拟 iphone 睡眠按钮)的方法。

This linkmight help.

链接可能会有所帮助。