3

In iBook, user can adjust the screen brightness via a slider, right?

What should I do to implement that? Which class or function I should use to control the screen brightness?

Thanks

Jack
  • 3,913
  • 8
  • 41
  • 66

3 Answers3

5

As of iOS5 you can adjust display brightness using the following:

[UIScreen mainScreen].brightness = 0.5;
jrturton
  • 118,105
  • 32
  • 252
  • 268
1

Hi I find on web this open source code from alec jacobson

- (void) set_brightness:(float) new_brightness {
CGDirectDisplayID display[kMaxDisplays];
CGDisplayCount numDisplays;
CGDisplayErr err;
err = CGGetActiveDisplayList(kMaxDisplays, display, &numDisplays);

if (err != CGDisplayNoErr)
    printf("cannot get list of displays (error %d)\n",err);
for (CGDisplayCount i = 0; i < numDisplays; ++i) {
    CGDirectDisplayID dspy = display[i];
    CFDictionaryRef originalMode = CGDisplayCurrentMode(dspy);
    if (originalMode == NULL)
        continue;
            io_service_t service = CGDisplayIOServicePort(dspy);

    float brightness;
    err= IODisplayGetFloatParameter(service, kNilOptions, kDisplayBrightness,
                                    &brightness);
    if (err != kIOReturnSuccess) {
        fprintf(stderr,
                "failed to get brightness of display 0x%x (error %d)",
                (unsigned int)dspy, err);
        continue;
    }

    err = IODisplaySetFloatParameter(service, kNilOptions, kDisplayBrightness,
                                     new_brightness);
    if (err != kIOReturnSuccess) {
        fprintf(stderr,
                "Failed to set brightness of display 0x%x (error %d)",
                 (unsigned int)dspy, err);
        continue;
    }
}       

}
Csabi
  • 3,097
  • 17
  • 59
  • 107
  • I used this code ,but it is showing me lots of errors,can you explain which frameworks I need to use for this...?Thanks – Sabby May 03 '12 at 13:59
1

It's a private API so, if you want to make your app available on the App Store, the answer is You can't. Which sucks on a number of levels.

You may want to raise a bugreport with Apple.

Stephen Darlington
  • 51,577
  • 12
  • 107
  • 152