2015-03-02 88 views

回答

0

經過一番搜索和擺弄之後,這裏有一個「未來證明」的方法來獲得不使用OS X 10.9中棄用的CGDisplayIOServicePort的顯示亮度。

- (float)getDisplayBrightness 
{ 
    float brightness = 1.0f; 
    io_iterator_t iterator; 
    kern_return_t result = 
     IOServiceGetMatchingServices(kIOMasterPortDefault, 
      IOServiceMatching("IODisplayConnect"), 
      &iterator); 

    // If we were successful 
    if (result == kIOReturnSuccess) 
    { 
     io_object_t service; 

     while ((service = IOIteratorNext(iterator))) 
     { 
      IODisplayGetFloatParameter(service, 
       kNilOptions, 
       CFSTR(kIODisplayBrightnessKey), 
       &brightness); 

      // Let the object go 
      IOObjectRelease(service); 
     } 
    } 

    return brightness; 
}