Looking to implement a day and night mode to your app? Ti.Brightness provides a series of APIs that allows you to read the iOS 7 screen brightness and be notified if it changes.
Getting the screen brightness
Reading the iOS 7 screen brightness level is easy. Just call the getScreenBrightness method as shown below. This method provides Titanium access to the underlying iOS [UIScreen mainScreen].brightness platform API.
var brightness = require('ti.brightness'); var level= brightness.getScreenBrightness(); Ti.API.info("Brightness Level:" + level);
* If you are running this in the simulator, 0.5 will always be returned.
Brightness Changed Event
You can use the changed event as shown in the following snippet to trigger an event after the user has adjusted their screen brightness. This event provides Titanium access to the name UIScreenBrightnessDidChangeNotification notification.
function onBrightChange(e){ Ti.API.info(JSON.stringify(e)); alert("Your Screen brightness is level: " + e.brightness); }; brightness.addEventListener('changed',onBrightChange);
* This event will not trigger in the simulator
In Action
The following movie shows the module in action and how Ti.Brightness can be used to add a dark and light theme to your app.