Check for display sleep/wake in a Network Extension in macOS?

I am aware of NSWorkspace.screensDidSleepNotification, but I am unsure if a Network Extension can listen for this notification. I tried it, but it doesn't appear to have any effect.


Is there some other way to detect if a macOS device's display is asleep within an extension?

Replies

I am aware of NSWorkspace.screensDidSleepNotification, but I am unsure if a Network Extension can listen for this notification.

I don’t think you’ll find a good way to do this. The approach you've suggested is not a good option because

NSWorkspace
is part of AppKit, and you really don’t want to link your Network Extension provider to AppKit. And that really speaks to the problem overall. Conceptually Network Extension providers exist at the networking layer in the system, far below the layers that manage the display.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"