Alternatives to applicationDidEnterBackground and applicationWillResignActive?

I've got an app that changes the screen brightness with [UIScreen mainScreen].brightness = newBrightness, and I want to restore the brightness to it's previous state when the user finishes using it.

I've tried these two delegate methods:

  • - (void)applicationDidEnterBackground:(UIApplication *)application
  • - (void)applicationWillResignActive:(UIApplication *)application

But without much success. I suspect my app must be in the foreground to change the brightness? When I change the brightness in didEnterBackgroundMethod, it has no effect at all. When I use willResignActive it does restore the brightness if I switch to another app, but it has no effect when I press the home button.

Are there any notifications or delegate methods that are executed before the app leaves the foreground?


It seems this happens to others as well: see this S.O. post.

Only way around it seems to be forgetting about setBrightness and simulating it by overlaying a black-semi-transparent on your view...


willResignActive should also be called when you press the home button before the application enters the background state.

This method is called to let your application know that it is about to move from the active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. An application in the inactive state continues to run but does not dispatch incoming events to responders.

This is also the behavior I witness. So, my guess (but it's just a guess) is that your app is not set to support background, so that when pressing the home button it is terminated. In this case applicationDidEnterBackground is not called.

I would suggest to check the info.plist file in your project for the UIApplicationExitsOnSuspend or "Select Application does not run in background" key.

Furthermore, you could try and put some breakpoints (or NSLog traces) in those functions and check whether they are effectively called as expected.

According to Apple´s DevForum it seems to be a bug that Apple don´t want to fix soon.

Need Your Help

Detect rapid user activity

I'm creating an ASP.Net MVC 5 website. In my website, there is a voting system which is very similar to the one StackOverflow uses. I have successfully created the system in which users submit the ...

Multiple NetStreams and performance

actionscript-3 flash flv netstream netconnection

I need to play multiple (66) synchronized .flv videos in flash. What I do: