views:

1074

answers:

1

Hello all, I searched around for a way to set the backlight level within an app on the iPhone. I found a solution here:

http://www.iphonedevsdk.com/forum/29097-post3.html

The problem I have is, when I add this to my app I get an error and a warning. My code is as follows:

#include "GraphicsServices.h"

- (void) viewWillAppear:(BOOL)animated
{

NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));
previousBacklightLevel = [bl floatValue];
//Error here : incompatible types in assignment

[bl release]; 

GSEventSetBacklightLevel(0.5f);
// Warning here : implicit declaration of function 'GSEventSetBacklightLevel'

}

//...The rest of my app

- (void)applicationWillTerminate:(UIApplication *)TheNameOfMyAppIsHere
{
    GSEventSetBacklightLevel(previousBacklightLevel);
}

I am unsure of what is causing this. I also don't really know what needs to be in my .h file here, but I have:

NSNumber *previousBacklightLevel;

EDIT// Changed

NSNumber *previousBacklightLevel

to

float previousBacklightLevel;

as suggested and this sorted the incompatible types in assignment error.

Now left with:

"_GSEventSetBacklightLevel", referenced from:

-[MyAppViewController viewWillAppear:] in MyAppViewController.o

-[MyAppViewController applicationWillTerminate] in MyAppViewController.o

symbol(s) not found

collect2: ld returned 1 exit status

Not sure how to fix this one either!

Any help would be appreciated,

// EDIT

All problems sorted. Thanks to all who helped me out. I really do appreciate it and can't wait till I can give a little back, by answering some questions.

Many thanks,

Stu

+4  A: 

The reason you are getting a warning is because GSEventSetBacklightLevel() is a private API not declared in any of of the SDK headers. If you are planning to submit this to the app store your app will get rejected if you call it. If this is for a jailbroken device, you can just declare the function yourself.

void GSEventSetBacklightLevel(float level);

The reason you are getting the error is because you are trying to assign a float (which is a scalar) to an NSNumber *. You probably want to change previousBacklightLevel to be a float.

Louis Gerbarg
Hmmm, still can't get this to work, could you give me some more code so I can see how it should look?
Stumf
What can't you get to work? Getting rid of the warning, or resolving the error?
Louis Gerbarg
Still can't get rid of error: incompatible types in assignment and now got error: incompatible type for argument 1 of 'GSEventSetBacklightLevel. I added void GSEventSetBacklightLevel(float level); to the GraphicsServices.h file. That solved the warning. Don't know how to fix my errors. What should declared in my .h and is there anything to be changed in my .m? What exactly is it that needs to be changed to a float? Thanks
Stumf
As Louis said, you have incorrectly defined previousBacklightLevel as an NSNumber, when it should be a float. Replace that line in your header with 'float previousBacklightLevel;'.
Brad Larson
Ok in my header I now have: float *prevBacklightLevel; In main I have : NSNumber* bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel"), CFSTR("com.apple.springboard")); prevBacklightLevel = [bl floatValue]; But still get incompatible types in assignment at the above line. Ideas? It is probably a basic mistake, I am new to this!
Stumf
Sorted the incompatible types in assignment error. Thanks to all. Please see above... stuck again...
Stumf
All problems sorted. Thanks to all who helped me out. I really do appreciate it and can't wait till I can give a little back, by answering some questions.
Stumf