7

I want when user call app from background to reaload one function from viewcontroller?

rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

9

Elaborating on nishith's answer:

Add the following code to your view controller you want to refresh

override func viewWillAppear() {
    super.viewWillAppear()
......
......
NotificationCenter.default.addObserver(self, selector:#selector(YourViewController.methodToRefresh), name: UIApplication.willEnterForegroundNotification, object: UIApplication.shared)
......
......
}

Always remember to cleanup when the view disappears in:

    override func viewWillDisappear(animated: Bool) {
    NotificationCenter.default.removeObserver(self)
}
Abhishek Arora
  • 395
  • 2
  • 12
4

You can register your controller for these notifications and reload your controller accordingly.

UIApplicationDidEnterBackgroundNotification
UIApplicationWillEnterForegroundNotification
nishith Singh
  • 2,968
  • 1
  • 15
  • 25