Rio*_*Rio 5 objective-c osx-snow-leopard
我为Mac开发了一个Menu Extra(menulet),但我想知道使用Menu Extra的机器是否已经进入睡眠状态.我实现了一个贪睡功能,但因为它是一个基于时间的方法,所以它相当不可靠.任何提示或建议将不胜感激!
谢谢!
您可能想要NSWorkspaceWillSleepNotification在NSWorkspace中查看.
诀窍是,您需要在NSWorkspace的notificationCenter上注册通知,而不是默认通知. 参见技术问答QA1340.
示例代码:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
733 次 |
| 最近记录: |