Dim iPhone Screen, but don't let it sleep

别等时光非礼了梦想. 提交于 2019-12-02 17:32:42

I'm pretty sure there's nothing in the official SDK.

[(id)[UIApplication sharedApplication] setBacklightLevel:0.3f]; // or whatever value

works, but is of course undocumented. The recent experience with UIGetScreenImage indicates that perhaps the right strategy with useful but undocumented APIs is to use them and see what happens.

Failing that, has anybody ever measured if the phone's power consumption goes down if it's showing a black image, or does it not help unless you can turn down the backlight?

I use a "nightstand" type alarm clock app that, if you double-tap its clock screen, dims the screen by some amount.

I believe what it's probably really doing is laying a partially-opaque black UIView over its entire content. I think the backlight isn't really dimmed, but the black color laid over the screen makes it seem dimmer. It works.

Can you set proximityState to trick the iPhone into thinking that it is close to someone's ear? This would work with the iPhone, but not the iPod touch. There is no way to selectively turn adjust the brightness ... apps that dim the screen typically do so by putting a partly transparent image over the current one.

Starting with iOS 5 you can set UIScreen's brightness:

This property is only supported on the main screen. The value of this property should be a number between 0.0 and 1.0, inclusive.

Brightness changes made by an app remain in effect only while the app is active. The system restores the user-supplied brightness setting at appropriate times when your app is not in the foreground. So if you change the value of this property, you do not need to record the previous value and restore it when your app moves to the background.

You can use this approach http://oleb.net/blog/2014/02/alarm-clock-apps-ios/

Just add a parameter into info.plist. And your app still run when your screen dim, your device locked.

When you debug, your app still run and never dim automatically, you just press lock button to test.

When you run your app without debug, you can see this feature do, like Music app of Apple, the music still play when device go to turn off screen.

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