I've successfully lowered the screen brightness of my app using this code
UIScreen.mainScreen().brightness = CGFloat(0.0)
However the auto brightness settings will increase the brightness over time. How could I make it stop adjusting to the brightness while inside my app?
As far as I know there is no way to disable auto brightness unless the user does it themselves in settings as Apple don't allow you to access general settings. You could have a function that lowers the brightness when something happens, which might work, depending on what app you're trying to make.
Related
I am trying to monitor whether the app is in the background or not, but while also tracking whether the screen is on or off, and there is no way to know if the screen is on/off. I need to know be able to tell these two combinations:
Screen is ON but app is in BACKGROUND
Screen is OFF but app is in FOREGROUND
I tried using WidgetsBindingObserver. The problem is this tells me the app is in the background when the screen goes off.
Did you try this package, it looks helpful !
I am making a clock app and I wanted to know how can I check what the current brightness level is set to and how can i adjust brightness in my application in xcode 4 with a UISlider instead of telling the user to go to their iphone/ipad setting app and adjust the brightness there? I can't find any code/api for it.
I have seen quite a few clock apps in appstore where the user can adjust the brightness of the display just by moving the finger up or down.
You're looking for the brightness property of UIScreen.
Sample code:
[UIScreen mainScreen].brightness = 0.5;
Available in iOS 5.0 and later.
Why can't I set screen brightness in applicationDidEnterBackground or applicationWillResignActive?
This is my code:
-(void)applicationDidEnterBackground:(UIApplication *)application {
[[UIScreen mainScreen] setBrightness:1.0];
}
Can't understand it...!? It works in applicationDidEnterForeground etc, just not when i close the app using the home button.
Is there any other solution to this problem?
Update August 2016:
Brightness changes made by an app remain in effect until the device is locked, regardless of whether the app is closed. The system brightness (which the user can set in Settings or Control Center) is restored the next time the display is turned on.
https://developer.apple.com/reference/uikit/uiscreen/1617830-brightness
Original Post July 2012:
You're not allowed to set the brightness just before exiting. This is not documented anywhere but the following post on the dev forums is helpful:
https://devforums.apple.com/thread/139813?start=0&tstart=0
What should happen is the system-wide brightness is restored when the app is backgrounded. There is a known bug where this doesn't actually happen until the next time the backlight is switched off and on.
You can reproduce this easily by setting the brightness to 0 and pressing the home key. The home screen will still be very dark. Lock then unlock your device and the system brightness is restored.
Please file a bug about this! On the same post an Apple employee posted that repeated bug reports are helpful.
I never tried to set screen brightness at applicationDidEnterBackground.
I think you can change brightness of your application by using UIView with black background color on top of everything. Then set the alpha of this UIView. Then the result will looks exactly like real screen brightness.
I use this alternative because this method is only available for iOS5.
[[UIScreen mainScreen] setBrightness:1.0];
I want to support iOS3,4 also.
I want to build an iPhone app, it's a simple concept. You know those wake-up lights, that function as an alarm clock but then with a fading light? That's what I want for an app.
There are two issues: screen locking and brightness setting. First of all, I like to prevent the screen from locking so the wake-up animation is still visible when you actually wake up. Second, I would like to set the brightness of the screen so when sleeping the screen is dim, but when waking the screen fades to a brighter level.
Unfortunately, I read all around the internets which stated that this impossible. You can prevent the app from locking with one single line of code, but you can't set the screen brightness programmatically without using a private api (which is not allowed for publishing).
Is there some sort of work-around to programmatically show the application on the screen when the alarm triggers, circumventing the lock screen? Could this perhaps be achieved with a local notification? Is there some other sort of nifty code to make the screen as dark as possible when sleeping, but putting it back to life (showing the app) when waking?
I hope some bright folks out here can help me out, because so far my concept seems impossible. Mucho kudo's for the chap that can help me out!
Bye,
Reinder
The wake up screen isn't possible using public APIs.
You can simulate turning the brightness down (and back up) in your app by simply painting the entire view black, or using very very dark colors (and displaying no status bar or a black status bar). But note that turning off the auto-lock timer all night may kill the users battery.
Simple answer: what you want is just not possible with the current public APIs of the iOS SDK.
I'm working on an application where it may be used in a dark area and the brightness is required to be lowered. I wanted to put this into the application, and thought that I could add a UIView with a black bg color and change the alpha, but this gets in the way of the user interaction.
Does anyone have an idea on how to do this without blocking human interaction?
Thanks
Set the UIView's userInteractionEnabled property to NO.