objective-c - 在 iOS 中关闭自动亮度
问题描述
自动亮度会覆盖我为我的应用程序设置的屏幕亮度值。我设置亮度
[[UIScreen mainScreen] setBrightness:0.1];
我想以编程方式关闭自动亮度
我正在开发企业应用程序,所以使用私有 api 没有问题
我试过UIScreenBrightnessDidChangeNotification
但它没有更新我的价值
- (void)viewDidLoad {
[super viewDidLoad];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserverForName:UIScreenBrightnessDidChangeNotification
object:nil
queue:nil
usingBlock:^(NSNotification *notification)
{
NSLog(@"Brightness changed: %f", [[UIScreen mainScreen] brightness]);
dispatch_async(dispatch_get_main_queue(), ^{
[[UIScreen mainScreen] setBrightness:0.1];
});
}];
}
解决方案
收听brightnessDidChangeNotification并在处理程序中将亮度设置回您想要的位置。
当然,您还需要添加代码以在应用程序处于后台后检查亮度(并且可能错过了通知)。
推荐阅读
- html - 如何在 javascript 中访问 svg 元素的内部 html 并进行更改?
- webgl - 如何在 webgl 中设置 SharedArrayBuffer 类型的 bufferData?
- c# - MongoDB 作为具有 WriteConcern Majority 和 ReadConcern Linearizable 的锁
- android - 如何在点击而不是长按时移动标记
- android - 当在本机反应中从android模拟器调用API时,显示网络请求的消息失败但不在真实设备中?
- java - java.lang.ClassCastException: com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeMultipart 不能转换
- java - 如何防止为某些类创建 java-doc
- neo4j - neo4j 的 CPU 使用率很高,我怎么知道它在做什么?
- scala - 大型 Docker 上下文减慢 docker-compose 构建
- opencv - 将python opencv库导入sikuliX