【问题标题】:Application session timeOut in cocoa application可可应用程序中的应用程序会话超时
【发布时间】:2014-02-21 05:59:16
【问题描述】:

各位朋友,我正在使用 cocoa 开发 MAC 桌面应用程序。我想在应用程序中添加会话超时。示例我在后台运行的应用程序用户不要触摸并且在应用程序中什么也不做。 20(我们需要设置)应用程序将返回主页(登录页面)会话超时。

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

【问题讨论】:

  • 您遇到的具体问题是什么?

标签: objective-c macos cocoa cocoa-touch


【解决方案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];
}    

基本上所有的鼠标和键盘事件都是通过这个方法进入你的应用的。你只需要重写它来设置你的计时器。

【讨论】:

  • 这对我有帮助。我确实需要将[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(applicationSessionTimeout:) object:nil] 行中的对象从nil 更改为self 才能使其正常工作。
猜你喜欢
  • 1970-01-01
  • 2019-06-23
  • 2015-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-04
相关资源
最近更新 更多