5分钟App无操作,自动跳转到登录页面

// 重写UIWindow下面的方法 sendEvent
- (void)sendEvent:(UIEvent *)event
{
    [super sendEvent:event];
    
    NSSet *allTouches = [event allTouches];
    if ([allTouches count] > 0) {

        // To reduce timer resets only reset the timer on a Began or Ended touch.
        UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;
        if (phase == UITouchPhaseBegan || phase == UITouchPhaseEnded) {
            if (!idleTimer) {
                [self windowActiveNotification];
            } else {
                [idleTimer invalidate];
            }
            if (idleTimeInterval != 0) {
                self.idleTimer = [NSTimer scheduledTimerWithTimeInterval:idleTimeInterval 
                                                                  target:self 
                                                                selector:@selector(windowIdleNotification) 
                                                                userInfo:nil repeats:NO];
            }
        }
    }
}


- (void)windowIdleNotification
{
    NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
    [dnc postNotificationName:KSDIdlingWindowIdleNotification 
                       object:self
                     userInfo:nil];
    self.idleTimer = nil;
}

- (void)windowActiveNotification
{
    NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
    [dnc postNotificationName:KSDIdlingWindowActiveNotification 
                       object:self
                     userInfo:nil];
}

 

posted @ 2015-05-27 14:21  CodingTom  阅读(815)  评论(0编辑  收藏  举报