我知道有一些方法可以在OS X上使用IOKit框架获得系统空闲时间,但我想知道是否有可用的通知。
我可以创建一个计时器来检查空闲时间是否大于x,这很好。如果我在几秒钟后检测到空闲模式并不重要。
问题是检测Mac何时不再闲置。我希望我的应用尽快显示通知,而不是几秒钟之后。
有没有办法收到通知? (iChat似乎有一个)
答案 0 :(得分:8)
这来自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];
}
答案 1 :(得分:1)
$('form').submit(function(e){
var name = $(this).find('input[name=name]').val();
// do smth with name
return true;
});