I've tried registering for NSWorkspaceDidWakeNotification
with [NSNotificationCenter defaultCenter]
, but it never fires when my MacBook Pro wakes from sleep. Other notifications that I register for fire, so it's not an issue with how I'm registering for it.
Basically I need to get notified when a user's machine has woken from sleep, and the user has logged back in, or the machine has woken and the user is back in their account, in the case that the login screen wasn't displayed to them. If I have to handle that with multiple notifications, that's fine as well.
Any thoughts?
Thanks!
Cody
The notification NSWorkspaceDidWakeNotification
does not come from the default notification center. This works:
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
selector:@selector(wakeFromSleep:)
name:NSWorkspaceDidWakeNotification
object:nil];
There exists the Apple Q&A 1340 regarding this question.
This covers only the waking aspect of your question. You don't get a notification when you log in originally, because you app is not running then. But you probably mean the password prompt for unlocking after sleep, and there you are fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With