GED125
GED125

Reputation: 496

Swift: Determine Active View Controller when applicationDidEnterBackground is called

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?

Upvotes: 1

Views: 777

Answers (1)

ppalancica
ppalancica

Reputation: 4277

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...

Upvotes: 1

Related Questions