Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

adjusting screen brightness

ecumeecume Posts: 80Registered Users
edited November 2011 in iPhone SDK Development
I assume you need to jailbreak to get access to system controls like this, but I'll throw this out there in case someone has discovered a handy solution...
Post edited by ecume on
«1

Replies

  • lapselapse Posts: 211Registered Users
    edited November 2008
    I believe the application 'Light' was removed from the store for messing with the screen brightness.
  • SkylarECSkylarEC Posts: 74Registered Users
    edited November 2008
    Yes, Apple will reject your app if you mess with the brightness. Although, if you still want to do it, you'd get the current brightness like this:
    -(void)getBacklightLevel;{
    	NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));
    	 previousBacklightLevel = [bl floatValue]; //a variable to store the previous level so you can reset it.
    	 [bl release];
    }
    

    And to set the backlight level, add this line
    GSEventSetBacklightLevel(newLevel); //The new level: 0.0 - 1.0.
    

    In order for this to work, you will need to include GraphicsServices.h. Depending on where you get your headers, you may need to add the GSEventSetBacklightLevel(float value); method to the headers, else the method won't quite work. [Some have reported kernel panics by not amending the header, but that has not been my experience]
  • wuf810wuf810 Posts: 1,052Registered Users @ @ @ @
    edited March 2009
    SkylarEC wrote: »
    Yes, Apple will reject your app if you mess with the brightness. Although, if you still want to do it, you'd get the current brightness like this:
    -(void)getBacklightLevel;{
    	NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));
    	 previousBacklightLevel = [bl floatValue]; //a variable to store the previous level so you can reset it.
    	 [bl release];
    }
    

    And to set the backlight level, add this line
    GSEventSetBacklightLevel(newLevel); //The new level: 0.0 - 1.0.
    

    In order for this to work, you will need to include GraphicsServices.h. Depending on where you get your headers, you may need to add the GSEventSetBacklightLevel(float value); method to the headers, else the method won't quite work. [Some have reported kernel panics by not amending the header, but that has not been my experience]

    wow sorry to raise such as an old thread, but does anyone know if this still works. I can't seem to return the current backlight value anymore (I'm sure it worked once)....its for a private app BTW so no App store violations

    TIA, Michael.
  • lewislewis Posts: 4New Users
    edited May 2009
    lapse wrote: »
    I believe the application 'Light' was removed from the store for messing with the screen brightness.

    I've seen two applications ("Astronomy Flashlight" and "Flashlight.") in the store that adjust the screen's brightness one way or another. They probably don't adjust the system brightness but they seem to have a way to "dim" the screen. Any ideas? It appears possible if (at least) two apps have made it into the store.
  • arutadarutad Posts: 11Registered Users
    edited May 2009
    Sneaky..!
    SkylarEC wrote: »
    In order for this to work, you will need to include GraphicsServices.h. Depending on where you get your headers, you may need to add the GSEventSetBacklightLevel(float value); method to the headers, else the method won't quite work. [Some have reported kernel panics by not amending the header, but that has not been my experience]
  • ftmftm Posts: 523Registered Users
    edited May 2009
    I think Flashlight may just be using different color backgrounds... gray's appear dimmer than whites.
    <a href="http://fasterthanmonkeys.com" target="_blank">app_showcase.jpg</a><br />
    <br />
    Website: <a href="http://fasterthanmonkeys.com" target="_blank">http://fasterthanmonkeys.com</a><br />
    <br />
    <a href="
  • lewislewis Posts: 4New Users
    edited May 2009
    ftm wrote: »
    I think Flashlight may just be using different color backgrounds... gray's appear dimmer than whites.

    Perhaps, but that doesn't explain how "Astronomy Flashlight" works and even if "Flashlight." does just use grays, how does it fade from one color to the gray?
  • wuf810wuf810 Posts: 1,052Registered Users @ @ @ @
    edited May 2009
    lewis wrote: »
    Perhaps, but that doesn't explain how "Astronomy Flashlight" works and even if "Flashlight." does just use grays, how does it fade from one color to the gray?

    they don't adjust the backlight levels...all they are doing is adjusting the alpha level of the top (red) view.
  • lewislewis Posts: 4New Users
    edited May 2009
    wuf810 wrote: »
    they don't adjust the backlight levels...all they are doing is adjusting the alpha level of the top (red) view.

    Oh, I see. Thanks.

    So does anyone know how to find the GraphicsServices library? I know I won't be able to submit it to the App Store, but I can still use it personally, can't I? I located the GraphicsServices.framework (several, actually), but when I try and expand it there are no headers listed? Did Apple just remove access to this completely or is there something else that needs to be done? TIA.
  • wuf810wuf810 Posts: 1,052Registered Users @ @ @ @
    edited May 2009
    lewis wrote: »
    Oh, I see. Thanks.

    So does anyone know how to find the GraphicsServices library? I know I won't be able to submit it to the App Store, but I can still use it personally, can't I? I located the GraphicsServices.framework (several, actually), but when I try and expand it there are no headers listed? Did Apple just remove access to this completely or is there something else that needs to be done? TIA.

    check out this link The iPhone SDK: APIs Apple Didn't Want You to Know About | O'Reilly Media

    It has all the info you need but its quite complicated if you are new to this sort of stuff.

    M.
  • Black ScytherBlack Scyther Posts: 36Registered Users
    edited September 2009
    Sory for digging up this thread but i have a problem with that and hours of searching at google were unsuccessful.

    Do I need to jailbreak my device to read the springboard.plist?
    NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));
    

    bl is always nil on my device. :(
  • wuf810wuf810 Posts: 1,052Registered Users @ @ @ @
    edited September 2009
    Sory for digging up this thread but i have a problem with that and hours of searching at google were unsuccessful.

    Do I need to jailbreak my device to read the springboard.plist?
    NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));
    

    bl is always nil on my device. :(

    This hasn't worked for me for a while. May have only worked in the early 2.x versions.

    Not sure if anyone else has found another way to do it...
  • Black ScytherBlack Scyther Posts: 36Registered Users
    edited September 2009
    wuf810 wrote: »
    This hasn't worked for me for a while. May have only worked in the early 2.x versions.

    Not sure if anyone else has found another way to do it...

    Well, GSEventSetBacklightLevel works very well and i find it quite odd if there isn't any get method. But I can't find any in the classdump.
  • wuf810wuf810 Posts: 1,052Registered Users @ @ @ @
    edited September 2009
    Well, GSEventSetBacklightLevel works very well and i find it quite odd if there isn't any get method. But I can't find any in the classdump.

    Yes confirmed. As you say setting the level works but trying to find the current level had changed.

    Anyone?
  • Black ScytherBlack Scyther Posts: 36Registered Users
    edited October 2009
  • nirnir Posts: 3New Users
    edited January 2011
    *push* Does anyone have a solution yet?

    GSEventSetBacklightLevel works fine on 4.2. Didn't try getting the level.
    There is another problem, though. Once I lock the phone and press the home button to use it again, the brightness is back to it's state before I changed it in my app.

    Any way to save the changes so they'll last?

    Thanx,
    Nir.
  • WinmaxWinmax Posts: 2New Users
    edited February 2011
    I'm also trying to get this working, but i have no success at all :(

    all i get is this error:
    [COLOR="Red"]
    "_GSEventSetBacklightLevel", referenced from:[/COLOR]
    -[MainViewController setBacklightLevel:] in MainViewController.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    

    Someone could give me a hint?

    Greetings
    Max
  • chenxintaochenxintao Posts: 1New Users
    edited April 2011
    nir wrote: »
    GSEventSetBacklightLevel works fine on 4.2. Didn't try getting the level.
    There is another problem, though. Once I lock the phone and press the home button to use it again, the brightness is back to it's state before I changed it in my app.

    Any way to save the changes so they'll last?

    Thanx,
    Nir.

    Hi,I want to use GSEventSetBacklightLevel, and I have #import "GraphicsServices.h", but there is a error. "_GSEventSetBacklightLevel", referenced from: .... symsbol not found.
    And I can't find GraphicsServices.framework.How can I do to use GSEventSetBacklightLevel ?
  • WinmaxWinmax Posts: 2New Users
    edited April 2011
    chenxintao wrote: »
    Hi,I want to use GSEventSetBacklightLevel, and I have #import "GraphicsServices.h", but there is a error. "_GSEventSetBacklightLevel", referenced from: .... symsbol not found.
    And I can't find GraphicsServices.framework.How can I do to use GSEventSetBacklightLevel ?

    Hi,
    i Managed to get it working, maybe you/someday some else can find your/his solution with my code snip.

    I used to change the backlight level with a UISlider, and programmatically with some "pulse" effect.

    some vars needed in my code
    // init global vars
    	_currentBacklightLevel = 0.2f;
    	[self setBacklightLevel:_currentBacklightLevel];
    	_pulseBacklightDirection = 0; // 0 = off, 1 = up, 2 = down
    


    Creating my slider
    // create brightnessSlider
    	brightnessSlider = [[UISlider alloc] initWithFrame:CGRectMake(18.0f, 420.0f, 258.0f, 23.0f)];
    	[brightnessSlider addTarget:self action:@selector(brightnessSliderChanged:) forControlEvents:UIControlEventValueChanged];
    	[brightnessSlider setBackgroundColor:[UIColor clearColor]];
    	brightnessSlider.minimumValue = 0.0;
    	brightnessSlider.maximumValue = 1.0;
    	brightnessSlider.continuous = YES;
    	brightnessSlider.value = _currentBacklightLevel;
    	[self.view addSubview:brightnessSlider];
    


    The main method, remember you won't pass appstore policy with this.
    - (void)setBacklightLevel: (float)newLevel {
    [INDENT][(id)[UIApplication sharedApplication] setBacklightLevel:newLevel]; // newLevel between 0.0f and 1.0f[/INDENT]
    }
    



    My pulse function, just some little play i made
    - (void)pulseBacklight {
    		
    	
    	if (_pulseBacklightDirection > 0) {		
    		if (_pulseBacklightDirection == 1) {
    			if (_currentBacklightLevel < 0.975f) _currentBacklightLevel += 0.025f;
    			else _pulseBacklightDirection = 2;
    			
    		}
    		else if (_pulseBacklightDirection == 2) {
    			if (_currentBacklightLevel > 0) _currentBacklightLevel -= 0.025f;
    			else _pulseBacklightDirection = 1;
    		}
    		[self setBacklightLevel: _currentBacklightLevel];
    		brightnessSlider.value = _currentBacklightLevel;
    		[self performSelector:@selector(pulseBacklight) withObject:nil afterDelay:0.01f];
    	}
    	else {
    		[self setBacklightLevel:0.5f];
    		_currentBacklightLevel = 0.5f;
    	}
    
    
    }
    

    Hope someday someone will see this, smile, and get his work done ;)

    Greetings
    Max
  • RomanRobotRomanRobot Posts: 46Registered Users
    edited August 2011
    wuf810 wrote: »
    they don't adjust the backlight levels...all they are doing is adjusting the alpha level of the top (red) view.

    Hey I wanted to know. Since we're not allowed to tamper with the backlight, does dimming the screen by putting a black background and lowering the alpha of everything in front of it offer any energy savings? Anything close to lowering the backlight or not worth it? Does it actually cost more?
  • jimmyyjleejimmyyjlee Posts: 3New Users
    edited November 2011
    where can i to get "GraphicsServices.h." this file ? thanks
    SkylarEC wrote: »
    Yes, Apple will reject your app if you mess with the brightness. Although, if you still want to do it, you'd get the current brightness like this:
    -(void)getBacklightLevel;{
    	NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));
    	 previousBacklightLevel = [bl floatValue]; //a variable to store the previous level so you can reset it.
    	 [bl release];
    }
    

    And to set the backlight level, add this line
    GSEventSetBacklightLevel(newLevel); //The new level: 0.0 - 1.0.
    

    In order for this to work, you will need to include GraphicsServices.h. Depending on where you get your headers, you may need to add the GSEventSetBacklightLevel(float value); method to the headers, else the method won't quite work. [Some have reported kernel panics by not amending the header, but that has not been my experience]
  • DomeleDomele Posts: 2,990Registered Users @ @ @ @ @
    edited November 2011
    UIScreen now has a method to adjust the brightness. Look in the docs.

    Edit: Changed UIDevice to UIScreen. Thanks for that correction BrianSlick.
    If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.<br />
    <br />
    New app - See screenshots and details at <a href="http://www.globaclock.com" target="_blank">www.globaclock.com</a>.<br />
    <br />
    If you want to
  • BrianSlickBrianSlick Treadmill Desk Ninja Northern Virginia / DCPosts: 10,067Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    edited November 2011
    Domele wrote: »
    UIDevice now has a method to adjust the brightness. Look in the docs.

    Which method?

    Edit: You mean UIScreen.
  • jimmyyjleejimmyyjlee Posts: 3New Users
    edited November 2011
    Domele wrote: »
    UIScreen now has a method to adjust the brightness. Look in the docs.

    Edit: Changed UIDevice to UIScreen. Thanks for that correction BrianSlick.

    hi
    can you tell me which method can adjust brightness if iOS 4.x, 3.x ?
    thank you

    jimmy
  • DomeleDomele Posts: 2,990Registered Users @ @ @ @ @
    edited November 2011
    The method was only introduced in iOS 5, there is no way to truly adjust the screen's brightness in iOS 5-.
    If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.<br />
    <br />
    New app - See screenshots and details at <a href="http://www.globaclock.com" target="_blank">www.globaclock.com</a>.<br />
    <br />
    If you want to
«1
Sign In or Register to comment.