'How to implement android's onResume() function in swift?

I'm using an observer like below to run code when the app comes back to the app from the background

However, if the app is run after a day or so, the observer does not run.

Is there a way to make the observer run even if the app runs after a day or two, or to have the same effect as onResume() in android?

NotificationCenter.default.addObserver(self, selector: #selector(enterForeground), name: UIApplication.didBecomeActiveNotification, object: nil)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source