0

In my application i want to do a session timeout after some time of inactivity. But if the user interacts with the app the timer needs to be reset.

Main concern is this should be implemented in part of the application not for the whole application, so is there any alternative for subclassing UIApplication to detect user interaction.

I do have a base class for those particular controller but touch or gesture delegates are not getting called in base class.

How can I detect user interaction for few controllers.

Thanks in advance for any ideas and help.

Shruti
  • 1,849
  • 1
  • 13
  • 21

1 Answers1

0

So, I figured out a way. In my base class, I was setting tap gesture on view earlier.

    let tap =  UITapGestureRecognizer(target: self, action: nil)
    tap.delegate = self
    tap.cancelsTouchesInView = false
    view.addGestureRecognizer(tap)

so instead of view.addGestureRecognizer(tap) now I am adding gesture on window

    if let window = UIApplication.shared.keyWindow {
        window.addGestureRecognizer(tap)
    }

and I implemented UIGestureRecognizerDelegate

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { 
 // My Code here
   return true
}

So, Now my base class is able to detect any taps and calling the delegate.

Please Note: Adding this delegate/ gesture is not effecting the touch or gesture on any of the other views of my child classes.

Shruti
  • 1,849
  • 1
  • 13
  • 21