Objective c 知道系统何时在额外菜单中进入睡眠状态?

Objective c 知道系统何时在额外菜单中进入睡眠状态?,objective-c,osx-snow-leopard,Objective C,Osx Snow Leopard,我为Mac开发了一个额外菜单(menulet),但我想知道使用额外菜单的机器是否已进入睡眠状态。我实现了一个snooze函数,但由于它是基于时间的方法,所以它相当不可靠。任何提示或建议将不胜感激 谢谢 您可能想签出NSWorkspaceWillSleepNotificationin. 诀窍是,您需要在NSWorkspace的notificationCenter上注册通知,而不是默认通知 示例代码: - (void) receiveSleepNote: (NSNotification*) note

我为Mac开发了一个额外菜单(menulet),但我想知道使用额外菜单的机器是否已进入睡眠状态。我实现了一个snooze函数,但由于它是基于时间的方法,所以它相当不可靠。任何提示或建议将不胜感激


谢谢

您可能想签出
NSWorkspaceWillSleepNotification
in.
诀窍是,您需要在NSWorkspace的notificationCenter上注册通知,而不是默认通知

示例代码:

- (void) receiveSleepNote: (NSNotification*) note
{
    NSLog(@"receiveSleepNote: %@", [note name]);
}

- (void) fileNotifications
{
    // These notifications are filed on NSWorkspace's notification center, not the default 
    // notification center. You will not receive sleep/wake notifications if you file 
    // with the default notification center.
    [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self 
            selector:@selector(receiveSleepNote:) 
            name: NSWorkspaceWillSleepNotification object:nil];
}