Thanks for the clarification. That helps. While you confirm if there is a way to distinguish between a dark wake and actual wake, would checking if any display is "awake" on a "wake" event be conclusive to know if its a dark wake or a full wake? Something like the below
- (void)wake {
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2000 * NSEC_PER_MSEC));
__weak typeof(self) weakSelf = self;
dispatch_after(delay, dispatch_get_main_queue(), ^{
__strong typeof(weakSelf) self = weakSelf;
if (!self) return;
BOOL displayAwake = [self isAnyDisplayAwake];
if (!displayAwake) {
// Dark wake ?
return;
}
});
// Genuine wake ?
}
- (BOOL)isAnyDisplayAwake {
uint32_t displayCount = 0;
CGGetOnlineDisplayList(0, NULL, &displayCount);
if (displayCount == 0) return NO;
CGDirectDisplayID *displays = (CGDirectDisplayID *)
calloc(displayCount, sizeof(CGDirectDisplayID));
if (!displays) return NO;
BOOL anyDisplayAwake = NO;
if (CGGetOnlineDisplayList(displayCount, displays, &displayCount) == kCGErrorSuccess) {
for (uint32_t i = 0; i < displayCount; i++) {
if (!CGDisplayIsAsleep(displays[i])) {
anyDisplayAwake = YES;
break;
}
}
}
free(displays);
if (!anyDisplayAwake) {
return NO;
}
return YES;
}
Topic:
App & System Services
SubTopic:
Networking
Tags: