1

Is there a way for me to determine the ViewController that was active when a user hits the Home button and the app delegate function applicationDidEnterBackground function is called?

GED125
  • 476
  • 4
  • 18
  • Have a look here: http://stackoverflow.com/questions/24825123/get-the-current-view-controller-from-the-app-delegate – ppalancica Apr 08 '16 at 18:22
  • I'm not very good with Objective-C, but I'll try to translate this post to Swift. :) – GED125 Apr 08 '16 at 18:24

1 Answers1

1

So this line:

let vc: UIViewController = self.window!.rootViewController!

will give you the root view controller in Swift (assuming that you use that line in some method inside AppDelegate), but if you have containers (such as UITabBarController) -- you may need to go on that hierarchy for additional checks/inspections...

ppalancica
  • 4,236
  • 4
  • 27
  • 42