iOS监听用户20分钟是否有操作

如果20分钟没有任何操作,需要重新登录

1.让新建的类继承UIApplication。

2.重载sendEvent方法。

 - (void)sendEvent:(UIEvent *)event
  {

   //这里一定不能漏掉,否则app将不能成功启动。

   [super sendEvent:event];

   NSSet *allTouches = [event allTouches];

  if ([allTouches count] > 0)

  {

          UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;

          if (phase == UITouchPhaseBegan)

          {

                   NSLog(@"send event");

          }

  }

}

3、发送通知

- (void)freeTimeNotification:(NSNotification *)notifi {
[kNotificationCenter postNotificationName:kUserEnterFreeTimeoutNotification object:nil];
  }

4.为了能让继承了UIApplication的AppDelegate起作用,需要将main.m中的更改为:

 return UIApplicationMain(argc, argv, NSStringFromClass
([AppDelegate class]),NSStringFromClass([AppDelegate class])); 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容