Unable to reset brightness on application exit iOS - iphone

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.

Related

Disable auto brightness inside app

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.

Dim iPhone back light on upside down

I have seen on an iOS application 'Sleep Cycle Alarm Clock' that when the iPhone is facing screen down (towards the floor) they have managed to dim the back light of the screen. I have been searching all over the internet and can't find the API that provides this functionality.
I am guessing that they achieve this by measuring acceleration on the device from gravity and dimming the back light accordingly, which I have no problem with. I just don't know how they have dimmed the back light (including the status bar!). It's not a semi-transparent black UIView overlayed on the superview, the light definitely switches off.
The detection isn't the issue, it's the dimming that I don't know how to do.
Can anyone point me to the correct method/API documentation? I'm using the iOS 6 SDK.
Thanks
EDIT:
Sorry guys, appears that I was wrong. Further investigation leads me to believe they haven't dimmed the backlight. The instructions stay over the superview temporarily. I think they actually overlay a black image and remove the status bar. My apologies! To get around the orientation lock for orientation detection I think they use the accelerometer.
Detecting if the device is face down can be done by using UIDevice orientation. This will return UIDeviceOrientationFaceDown when the screen is facing toward the floor.
Have a look at the UIScreen class for a couple of methods related to brightness.
Try this:
[[UIScreen mainScreen] setBrightness:0.5]; //Any value you think works
for more information about UIScreen and what you can do with it look at the documentation:
UIScreen Apple Documentation
EDIT: Just read the comments on the other answer, what kind of problems does this method cause?

Letting user adjust brightness in application

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.

How to relaunch an Air-based iOS application from the very first page?

My application is an Air-based iPhone app. It opens with the last page I visited before clicking the Home button, each time I relaunch the app, while I need to open with the splash screen onward. How can I resolve this issue?
Thank you for any help.
When you press the Home button, you don't terminate a running app. I'm sure that many of us developers have stuck with this mental model of how iOS used to work without multitasking.
So, the splash screen, or rather, the default image (Default.png) should really appear once (when your application launches). Some times, the default image appears when coming out from the background state, but this happens only if your app takes too long to show its UI. In fact, on fast iPhones, the default image disappears almost instantly even on launch (for well-written apps, that is).
I should also note that Apple actively discourages the use of the default image for splash screens. These should only be used for creating an illusion of transition, from a "launching state" (which the default image is supposed to portray), to the running state.
However, if you really have to show a splash screen every time, you should implement such a mechanism in code. applicationDidBecomeActive: is a good place to start, if you are writing code in Objective-C.
I don't know the event model in Air, so I can't really give you any hints for that.
The above answer, though old, does not answer the question. Sure, Apple gives guidelines regarding splash screen and all, but the poster asks how to prevent the app from resuming from it's previous position. If you want the app to terminate when put in the background you need to look into the UIApplicationExitsOnSuspend option. There's also an Adobe blog post explaining a bit more about different background behaviors.

Several issues considering an iPhone wake-up light app

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.