gca*_*amp 11 macos cocoa notifications
我知道有一些方法可以在OS X上使用IOKit框架获得系统空闲时间,但我想知道是否有可用的通知.
我可以创建一个计时器来检查空闲时间是否大于x,这很好.如果我在几秒钟后检测到空闲模式并不重要.
问题是检测Mac何时不再空闲.我希望我的应用尽快显示通知,而不是几秒钟之后.
有办法收到通知吗?(iChat似乎有一个)
这是来自http://developer.apple.com/library/mac/#qa/qa1340/_index.html(来自比尔蜥蜴评论)
- (void) receiveSleepNote: (NSNotification*) note
{
NSLog(@"receiveSleepNote: %@", [note name]);
}
- (void) receiveWakeNote: (NSNotification*) note
{
NSLog(@"receiveWakeNote: %@", [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: NULL];
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
selector: @selector(receiveWakeNote:)
name: NSWorkspaceDidWakeNotification object: NULL];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3771 次 |
最近记录: |