有没有一种程序化的方法来监控Mac何时即将进入睡眠状态?我想监控用户有意让系统进入睡眠状态的时候以及系统自然准备进入睡眠状态的时候。
你可以像这样注册以下通知:
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(receiveSleepNotification:) name:NSWorkspaceScreensDidSleepNotification object:NULL];
您可以像这样注册唤醒通知:
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(receiveWakeNotification:) name:NSWorkspaceDidWakeNotification object:NULL];