首页 > 解决方案 > 在 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];
         });
     }];
}

标签: objective-ciphone-privateapibrightnessuiscreen

解决方案


收听brightnessDidChangeNotification并在处理程序中将亮度设置回您想要的位置。

当然,您还需要添加代码以在应用程序处于后台后检查亮度(并且可能错过了通知)。


推荐阅读