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

发布于 2024-09-27 22:46:55 字数 88 浏览 3 评论 0原文

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

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

雪若未夕 2024-10-04 22:46:56

您可以通过启用近距离监控来关闭显示。它将自动关闭屏幕,就像在“电话”应用程序中一样,只需将手机放在耳朵附近或将手指放在手机顶部的红外传感器上即可。

[UIDevice currentDevice].proximityMonitoringEnabled = YES;

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;
燃情 2024-10-04 22:46:56

您可以这样做(当然,使用私有 API):

在 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");

然后

SBDimScreen(port,YES); 

在您想要调暗或

SBDimScreen(port,NO);

取消调暗时使用。

在iOS6上:

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

然后使用:

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

“Dim”这里的意思是完全关闭屏幕。这是系统在通话过程中发生接近事件等情况时使用的方法。

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.

小嗲 2024-10-04 22:46:56

我知道的唯一方法,无论是公共的还是私人的,都是使用电源按钮。

您可以查看 -[UIApplication setProximitySensingEnabled:(BOOL)]-[UIApplication setIdleTimerDisabled:YES],这可能会带来一些有用的结果

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

清醇 2024-10-04 22:46:56

您是否尝试过:

[[UIScreen mainScreen] setBrightness: yourvalue];

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

Have you tried:

[[UIScreen mainScreen] setBrightness: yourvalue];

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

゛清羽墨安 2024-10-04 22:46:56

邻近功能并不适用于所有设备。对于这个问题,有一个更简单的解决方案,无需求助于私有 API。

Swift

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

如果没有 wantsSoftwareDimming,背光将永远不会完全关闭。
该文档有这样的警告句子:

默认值为 false。启用它可能会导致性能损失。

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.

北渚 2024-10-04 22:46:56

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

链接可能会有所帮助。

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

This link might help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文