gpt4 book ai didi

objective-c - 如何在 mac 中查找登录和注销事件?

转载 作者:搜寻专家 更新时间:2023-10-30 20:02:54 24 4
gpt4 key购买 nike

我对这个应用程序开发领域比较陌生。我试图在用户登录和注销事件期间获得通知。我已尝试使用 NSWorkSpaceNotifications,但它对我不起作用。

有人可以帮帮我吗

-(void)logInLogOutNotifications{
NSNotificationCenter *notCenter;
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[notCenter addObserver:self
selector:@selector(observerMethod)
name:NSWorkspaceWillPowerOffNotification object:nil];
}

-(void)observerMethod:(NSNotification *)senderNotification;{

NSLog(@"System Logout Notification is called***********************");

}

最佳答案

NSApplicationMain 开始 RunLoop。您正在从 main() 函数调用 logInLogOutNotifications 函数,因此您应该运行 runloop。或者在 applicationDidFinishLaunching

中调用 logInLogOutNotifications
-(void)logInLogOutNotifications{
NSNotificationCenter *notCenter;
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[notCenter addObserver:self
selector:@selector(observerMethod)
name:NSWorkspaceWillPowerOffNotification object:nil];
[[NSRunLoop currentRunLoop] run];
}

关于objective-c - 如何在 mac 中查找登录和注销事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17168123/

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