ASCScreenBrightnessDetector
Detects screen brightness changes and provides some useful delegate methods.
Install / Use
/learn @schneiderandre/ASCScreenBrightnessDetectorREADME
ASCScreenBrightnessDetector
ASCScreenBrightnessDetector lets you easily detect screen brightness changes and provides some useful delegate methods.
For Example it's very easy to switch between a day and night theme optimized for different lighting conditions:

Usage
This repository contains an example project that uses the methods provided by ASCScreenBrightnessDetector - just build and run to see it in action.
Please note: The screen brightness detection will only work on a real device, the Xcode Simulators screen brightness is always 0.5.
Wherever you want to use ASCScreenBrightnessDetector, import the header file as follows:
#import "ASCScreenBrightnessDetector.h"
or when using CocoaPods:
#import <ASCScreenBrightnessDetector/ASCScreenBrightnessDetector.h>
To detect the current screen brightness or style you can easily use:
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;
}
To continuously detect screen brightness changes implement ASCScreenBrightnessDetector as an instance variable, set the delegate and use the following delegate methods:
- (void)screenBrightnessDidChange:(CGFloat)brightness
{
NSLog(@"The new brightness is: %f", brightness);
}
- (void)screenBrightnessStyleDidChange:(ASCScreenBrightnessStyle)style
{
NSLog(@"The new style is: %u", style);
}
Properties
The object that acts as the delegate.
id<ASCScreenBrightnessDetectorDelegate> delegate;
The brightness level of the screen between 0.0 and 1.0, inclusive. (read-only)
CGFloat screenBrightness;
The style indicates if the screen brightness is dark or light and depends on the defined threshold. (read-only)
ASCScreenBrightnessStyle screenBrightnessStyle;
The threshold determines whether the brightness style is light or dark. It must have a value between 0.0 and 1.0, inclusive. The default value is 0.5.
CGFloat threshold;
Delegate Methods
Tells the delegate when the screens brightness changed and returns a float value between 0.0 and 1.0, inclusive.
- (void)screenBrightnessDidChange:(CGFloat)brightness;
Tells the delegate when the screens brightness style changed and returns an ASCScreenBrightnessStyle enumeration.
- (void)screenBrightnessStyleDidChange:(ASCScreenBrightnessStyle)style;
Installation
From CocoaPods
ASCScreenBrightnessDetector is available through CocoaPods, to install it simply add the following line to your Podfile:
pod "ASCScreenBrightnessDetector"
Manually
Drag the ASCScreenBrightnessDetector.h and ASCScreenBrightnessDetector.m source files to your project and you are done.
Author
André Schneider, @_schneiderandre
License
ASCScreenBrightnessDetector is available under the MIT license. See the LICENSE file for more info.
Related Skills
node-connect
349.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.7kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
