gpt4 book ai didi

macos - OS X 上系统空闲或不空闲时的通知

转载 作者:行者123 更新时间:2023-12-03 16:04:06 24 4
gpt4 key购买 nike

我知道有一些方法可以通过 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];
}

关于macos - OS X 上系统空闲或不空闲时的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6418210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com