I want to log analytics when user pop UIViewController
with swipe gesture (interactivePopGestureRecognizer
) or pressed on default back button on navigationController. I find a way to detect when user using swipe gesture:
extension AppCoordinator: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
if let coordinator = navigationController.topViewController?.transitionCoordinator {
coordinator.notifyWhenInteractionChanges(handleInteraction)
}
}
func handleInteraction(context: UIViewControllerTransitionCoordinatorContext) {
guard !context.isCancelled else {
return
}
//LOG EVENT HERE
}
}
But what about back button?