Hello,
I try to get notifications when the display is turned off (not the screensaver). I've tried the following code (part of it), but it don't work at all (the callback is never called).. I don't get where I did something wrong. Any help or relevant documentation link would be very appreciated ..
Thank, volfo
io_object_t disp_notifierObject;
void* disp_refCon = NULL;
kern_return_t disp_registerCode;
notifyPortRef = IONotificationPortCreate(kIOMainPortDefault);
display_wrangler = IOServiceGetMatchingService(
kIOMainPortDefault,
IOServiceNameMatching("IODisplayWrangler"));
// register to receive display sleep notifications
disp_registerCode = IOServiceAddInterestNotification(
notifyPortRef,
display_wrangler,
kIOGeneralInterest,
CBDisplaySleep,
NULL,
&disp_notifierObject);
if ( disp_registerCode != kIOReturnSuccess ) {
printf("IOServiceAddInterestNotification failed\n");
return 2;
}
CFRunLoopAddSource(
CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(notifyPortRef),
kCFRunLoopCommonModes );
IOObjectRelease (display_wrangler);