Reliable way to get machine wake up + user registered in Cocoa notification?

I tried registering for NSWorkspaceDidWakeNotification with [NSNotificationCenter defaultCenter] , but it never fires when my MacBook Pro wakes up from sleep. Other notifications that I register for launch, so that is not a problem with the way I register it.

Basically, I need to receive notifications when the user machine woke up from sleep, and the user logged in again, or the machine woke up and the user returned to his account if the login screen was not displayed on them. If I have to handle this with a few notifications, that's fine too.

Any thoughts?

Thanks!
Cody

+4
source share
1 answer

The NSWorkspaceDidWakeNotification notification NSWorkspaceDidWakeNotification not come from the default notification center. It works:

 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(wakeFromSleep:) name:NSWorkspaceDidWakeNotification object:nil]; 

There is an Apple Q & A 1340 on this issue.

This only applies to the awake aspect of your question. You do not receive a notification when you first log in, because the application does not work. But you probably mean the password hint for unlocking after sleep, and there you are fine.

+6
source

Source: https://habr.com/ru/post/1397882/


All Articles