w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to detect user inactivity since last touch on a particular viewcontroller in iOS?

Override the view's touches began method and reset a timer when you get touches.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    [self.timer invalidate];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self
selector:@selector(inactivityTimerFired) userInfo:nil repeats:NO];

    [super touchesBegan:touches withEvent:event];

You could target the view controller instead of self if you need to.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.