0

In my viewDidLoad, I add code to follow UIApplication.didBecomeActive notification as follows:

NotificationCenter.default.addObserver(self,
                                       selector: #selector(ViewController.applicationDidBecomeActive),
                                       name: UIApplication.didBecomeActiveNotification,
                                       object: UIApplication.shared)

The question is whether it is a given that once the notification is subscribed in viewDidLoad, the notification callback will not fire before viewDidLayoutSubviews() is called? It so happens on all my iOS devices across all iOS versions but it seems to be the source of bug if this is not true. Trying to figure out sources of all unreproducible bugs, not sure if this can be one of them.

mcskinner
  • 2,620
  • 1
  • 11
  • 21
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
  • If you are using `UIApplication.didBecomeActiveNotification` incorrectly, then sure, it could be a source of "bugs" in your app. Without providing any information about what you're doing, no other answer could be offered. – DonMag Jul 09 '20 at 18:23
  • I just wanted to know what is supposed to be the order of calls -- viewDidLoad, viewDidLayoutSubviews, and UIApplication.didBecomeActiveNotification. Is there a supposed order that is followed or UIApplication.didBecomeActiveNotification can be called even before viewDidLoad? – Deepak Sharma Jul 10 '20 at 08:40
  • You probably want to read up on Application and Controller lifecycles. Search for `UIApplication lifecycle` and `UIViewController lifecycle`. It will help you understand when events happen, as well as what you should (and should not) do during each step. – DonMag Jul 10 '20 at 12:29

0 Answers0