0

my question is related to touch event which is Global in app

This is my scenario,

I Have an App with 15 screens, When first screen launches the timer starts, User goes from one screen to another screen randomly, In that case i need to reset the timer, If timer reaches to (say 120 seconds ) i have to destroy the current user session and logout n starts from first screen.

The implementation code for startLogoutTimer resetLogoutTimer and stopLogoutTimer is in AppDelegate class, if User navigates to any screen and touches the screen, i need to execute the methods of startLogoutTimer, resetLogoutTimer and stopLogoutTimer based on action but without message call to AppDelegate from every class (Screen/ViewController).

Thank You.

Nasir
  • 1,617
  • 2
  • 19
  • 34

3 Answers3

3

My above Problem is Solved. I added the below code into AppDelegate class

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetLogoutTimer) name:UITouchPhaseBegan object:nil];

Now where ever I touch on screen, my timer restarts.

Undo
  • 25,519
  • 37
  • 106
  • 129
Nasir
  • 1,617
  • 2
  • 19
  • 34
0

Create category for UIView and handle touches in it.

@implementation UIView (Touch)

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];
    [((Appdelegate*)[UIApplication sharedApplication].delegate) resetLogoutTimer];

}

Or you cand do it the same with swizzling

oxigen
  • 6,263
  • 3
  • 28
  • 37
  • Thank you, the logic works correct, but i have minor problem, when I use catagory the method `touchedEnded` calls for three times instead of one, Does you have any other way which is related to `UIWindow`, because every App has only one **Window**, which I can use for handling the Touch Event. – Nasir Jan 27 '15 at 05:05
0

Hi below two links solved my problem

iOS perform action after period of inactivity (no user interaction)

Timing Out An Application Due To Inactivity

Community
  • 1
  • 1
Nasir
  • 1,617
  • 2
  • 19
  • 34