检测当前屏幕亮度:
ASCScreenBrightnessDetector *brightnessDetector = [ASCScreenBrightnessDetector new];
NSLog(@"Screen brightness: %f", brightnessDetector.screenBrightness);
ASCScreenBrightnessStyle style = brightnessDetector.screenBrightnessStyle;
switch (style) {
case ASCScreenBrightnessStyleDark:
// Do something, e.g. set a dark theme.
break;
case ASCScreenBrightnessStyleLight:
// Do something else, e.g set a light theme.
break;
}
响应屏幕亮度变化的delegate函数:
- (void)screenBrightnessDidChange: (CGFloat)brightness
{
NSLog(@"The new brightness is: %f", brightness);
}
- (void)screenBrightnessStyleDidChange:(ASCScreenBrightnessStyle)style
{
NSLog(@"The new style is: %u", style);
}