iPhone brightness private API not working properly
Asked Answered
B

1

3

I am trying to set the brightness of the backlight, but it's acting very strangely. I am using the private API:

[(id)[UIApplication sharedApplication] setBacklightLevel:1.0f];

However, when I call this, the screen dims, not becoming 100% bright like I thought it would. I have tested this with a variety of numbers, and here is what I got:

0.2: dark

0.3: light

0.4: dark

0.5: dark

0.6: light

0.7: dark

0.8: dark

0.9: dark

1.0: dark

1.1: dark

1.2: light

1.3: dark

1.4: dark

1.5: light

Some of the values were slightly brighter than the darkest values, but that is the overall trend. It doesn't seem like the pattern makes any sense. Does anyone know what scale the brightness should be on?

Bircher answered 19/1, 2011 at 20:18 Comment(5)
I'm not capable of answering your question, but I wish to draw your attention the fact that applications using private APIs (this one included) will not be allowed onto the App Store by Apple. I apologize if you're already aware of this issue, but I thought it might save you your time, in case you are not :)Highboy
Yes, I'm aware of this. I do not intend to release this to the App Store.Bircher
Just to check: Do you have a header declaring this method as taking a float? Are there any warnings when you compile?Scad
I found a - (void)setBacklightFactor:(int)fp8;, maybe that matters? I haven't tried this though, so I'm not posting it yet as an answer. code.google.com/p/iphone-dev/source/browse/branches/…Helotry
Chuck, I didn't think it would make a difference (I had to declare the method for the -brightnessLevel but didn't have to for -setBrightnessLevel so I assumed it figured it out), but it did! Thanks! Submit this as an answer so I can accept it.Bircher
S
2

The problem is that the compiler doesn't know a method takes a float unless you declare it. So the float you pass in is getting converted to another type when you pass it and then that new bit pattern being reinterpreted as a float by the method. You just need to have the method declared in a header that file knows about and the float will be passed unaltered.

Scad answered 21/1, 2011 at 0:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.