Nasir
Nasir

Reputation: 1789

Global Touch Event in ios

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.

Upvotes: 0

Views: 1948

Answers (3)

Nasir
Nasir

Reputation: 1789

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.

Upvotes: 3

oxigen
oxigen

Reputation: 6263

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

Upvotes: 0

Related Questions