0

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?

Abhi Beckert
  • 32,787
  • 12
  • 83
  • 110

2 Answers2

0

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

ehrpaulhardt
  • 1,607
  • 12
  • 19
0

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...

OLD ANSWER:

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.

Community
  • 1
  • 1
sergio
  • 68,819
  • 11
  • 102
  • 123
  • The event is always being called, I've confirmed this with debugging. The problem is that the API to change the brightness doesn't have any effect, probably because the transition to background has already occurred. – Abhi Beckert Jan 27 '12 at 05:45