0

I want to know how does analytic frameworks detect screen transition? Like showing or presenting ViewController?

What I want to do is listening to all ViewController presentation event and check the view identifier. If the view identifier is of a special kind. I will do an additional step, such as tracking the view's presented time.

I remember that few years ago, you can do this (listen to presentation event), but I forgot if it was part of NotificationCenter or Darwin...

Currently, I think the only "Documented" way of doing this is by specifying completion block on present() function call. But that would mean I have to modify every call, and I want to avoid that

Ken White
  • 123,280
  • 14
  • 225
  • 444

1 Answers1

0

One approach (I think Firebase are doing something similar with their analytics SDK) is to swizzle the viewDidLoad and run the checks you intend

Some Examples - link - 1, link 2, link 3

Another could be to use a base class that will override this method and run the checks you would like....

class BaseViewContoller: UIViewContoller {
  override func viewDidLoad() {
   super.viewDidLoad()
   // check whatever you'd with
  }
}

....

final class MyActualViewController: BaseViewController {
  ....
}
CloudBalancing
  • 1,461
  • 2
  • 11
  • 22