Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-11-2008, 10:15 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 80
Default adjusting screen brightness

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...
ecume is offline   Reply With Quote
Old 11-11-2008, 10:36 AM   #2 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 211
Default

I believe the application 'Light' was removed from the store for messing with the screen brightness.
lapse is offline   Reply With Quote
Old 11-11-2008, 10:40 AM   #3 (permalink)
New Member
 
Join Date: Nov 2008
Posts: 74
Default

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:
Code:
-(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
Code:
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]
SkylarEC is offline   Reply With Quote
Old 03-29-2009, 04:32 PM   #4 (permalink)
Registered Member
 
Join Date: Sep 2008
Location: London, UK
Posts: 1,049
Default

Quote:
Originally Posted by SkylarEC View Post
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:
Code:
-(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
Code:
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.
wuf810 is offline   Reply With Quote
Old 05-01-2009, 09:13 PM   #5 (permalink)
New Member
 
Join Date: May 2009
Posts: 4
Default

Quote:
Originally Posted by lapse View Post
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.
lewis is offline   Reply With Quote
Old 05-01-2009, 10:17 PM   #6 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 11
Default

Sneaky..!

Quote:
Originally Posted by SkylarEC View Post
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]
arutad is offline   Reply With Quote
Old 05-02-2009, 09:59 AM   #7 (permalink)
ftm
FasterThanMonkeys.com
 
Join Date: Mar 2009
Location: Southern California
Posts: 523
Send a message via AIM to ftm
Default

I think Flashlight may just be using different color backgrounds... gray's appear dimmer than whites.
__________________


Website: http://fasterthanmonkeys.com

iScore Baseball Scorekeeper Top baseball scorekeeping app for iPhone
Bug Squash Reached #1 kids game in 15+ countries including USA, now with OpenFeint
Jam Packed! Fun puzzle game for all ages
Jam Packed Christmas Holiday puzzle game!
iScore Basketball Scorekeeper Best basketball scorekeeping application
ftm is offline   Reply With Quote
Old 05-02-2009, 12:16 PM   #8 (permalink)
New Member
 
Join Date: May 2009
Posts: 4
Default

Quote:
Originally Posted by ftm View Post
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?
lewis is offline   Reply With Quote
Old 05-02-2009, 12:33 PM   #9 (permalink)
Registered Member
 
Join Date: Sep 2008
Location: London, UK
Posts: 1,049
Default

Quote:
Originally Posted by lewis View Post
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.
wuf810 is offline   Reply With Quote
Old 05-03-2009, 03:38 PM   #10 (permalink)
New Member
 
Join Date: May 2009
Posts: 4
Default

Quote:
Originally Posted by wuf810 View Post
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.
lewis is offline   Reply With Quote
Old 05-03-2009, 03:57 PM   #11 (permalink)
Registered Member
 
Join Date: Sep 2008
Location: London, UK
Posts: 1,049
Default

Quote:
Originally Posted by lewis View Post
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.
wuf810 is offline   Reply With Quote
Old 09-25-2009, 09:19 AM   #12 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 36
Default

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?

Code:
NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));
bl is always nil on my device.
Black Scyther is offline   Reply With Quote
Old 09-25-2009, 11:13 AM   #13 (permalink)
Registered Member
 
Join Date: Sep 2008
Location: London, UK
Posts: 1,049
Default

Quote:
Originally Posted by Black Scyther View Post
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?

Code:
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...
wuf810 is offline   Reply With Quote
Old 09-28-2009, 02:14 AM   #14 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 36
Default

Quote:
Originally Posted by wuf810 View Post
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.
Black Scyther is offline   Reply With Quote
Old 09-28-2009, 05:08 AM   #15 (permalink)
Registered Member
 
Join Date: Sep 2008
Location: London, UK
Posts: 1,049
Default

Quote:
Originally Posted by Black Scyther View Post
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?
wuf810 is offline   Reply With Quote
Old 10-21-2009, 03:51 AM   #16 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 36
Default

*push* Does anyone have a solution yet?
Black Scyther is offline   Reply With Quote
Old 01-29-2011, 03:01 PM   #17 (permalink)
nir
Registered Member
 
Join Date: Jun 2010
Posts: 3
Default

Quote:
Originally Posted by Black Scyther View Post
*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.
nir is offline   Reply With Quote
Old 02-26-2011, 03:05 PM   #18 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 2
Default

I'm also trying to get this working, but i have no success at all

all i get is this error:

Code:
 
"_GSEventSetBacklightLevel", referenced from:
-[MainViewController setBacklightLevel:] in MainViewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Someone could give me a hint?

Greetings
Max
Winmax is offline   Reply With Quote
Old 04-16-2011, 10:08 PM   #19 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 1
Default

Quote:
Originally Posted by nir View Post
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 ?
chenxintao is offline   Reply With Quote
Old 04-17-2011, 06:27 AM   #20 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 2
Default

Quote:
Originally Posted by chenxintao View Post
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
Code:
	// init global vars
	_currentBacklightLevel = 0.2f;
	[self setBacklightLevel:_currentBacklightLevel];
	_pulseBacklightDirection = 0; // 0 = off, 1 = up, 2 = down

Creating my slider
Code:
	// 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.
Code:
- (void)setBacklightLevel: (float)newLevel {
[(id)[UIApplication sharedApplication] setBacklightLevel:newLevel]; // newLevel between 0.0f and 1.0f
}


My pulse function, just some little play i made
Code:
- (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
Winmax is offline   Reply With Quote
Old 08-23-2011, 02:54 PM   #21 (permalink)
Newcomer
 
Join Date: Jun 2011
Location: Caguas, PR
Age: 18
Posts: 46
Default

Quote:
Originally Posted by wuf810 View Post
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?
RomanRobot is offline   Reply With Quote
Old 11-02-2011, 08:32 AM   #22 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 3
Default where can i to get "GraphicsServices.h." this file ? thanks

where can i to get "GraphicsServices.h." this file ? thanks

Quote:
Originally Posted by SkylarEC View Post
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:
Code:
-(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
Code:
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]
jimmyyjlee is offline   Reply With Quote
Old 11-02-2011, 10:28 AM   #23 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,036
Default

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.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.

Last edited by Domele; 11-02-2011 at 06:13 PM.
Domele is offline   Reply With Quote
Old 11-02-2011, 12:31 PM   #24 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Quote:
Originally Posted by Domele View Post
UIDevice now has a method to adjust the brightness. Look in the docs.
Which method?

Edit: You mean UIScreen.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:

Last edited by BrianSlick; 11-02-2011 at 12:39 PM.
BrianSlick is offline   Reply With Quote
Old 11-03-2011, 04:53 AM   #25 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 3
Default

Quote:
Originally Posted by Domele View Post
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
jimmyyjlee is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,768
Threads: 89,201
Posts: 380,576
Top Poster: BrianSlick (7,129)
Welcome to our newest member, lucileadair
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:04 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0