gpt4 book ai didi

objective-c - cocoa 应用程序中的应用程序 session 超时

转载 作者:行者123 更新时间:2023-12-03 17:11:50 24 4
gpt4 key购买 nike

嗨 friend 们,我正在使用 cocoa 开发 MAC 桌面应用程序。我想在应用程序中添加 session 超时。例如,我在后台运行的应用程序用户不触摸并且在应用程序中不执行任何操作。 20后(我们需要设置)应用程序将返回主页(登录页面) session 超时。

将帮助我如何在 cocoa 应用程序中设置 session

最佳答案

使用自定义 NSApplication 类并覆盖 sendEvent:。像这样的事情:

- (void)sendEvent:(NSEvent *)event
{
[super sendEvent:event];

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(applicationSessionTimeout:) object:nil];
[self performSelector:@selector(applicationSessionTimeout:) withObject:self afterDelay:SESSION_TIMEOUT];
}

基本上所有鼠标和键盘事件都通过此方法进入您的应用程序。您只需覆盖它即可设置计时器。

关于objective-c - cocoa 应用程序中的应用程序 session 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21926447/

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