应用程序会话timeOut在cocoa应用程序中

时间:2014-02-21 05:59:16

标签: objective-c macos cocoa cocoa-touch

朋友们,我正在使用cocoa开发MAC桌面应用程序。我想在应用中添加会话时间。示例我在后台用户运行的应用程序不要在app中执行任何操作。 20(我们需要设置)后,应用程序将返回主页(登录页面)以供会话超时。

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

1 个答案:

答案 0 :(得分:1)

使用自定义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];
}    

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

相关问题