I have a label that displays the state of the app. as far as I can tell, there is no way to call UIApplicationDelegate protocol methods inside the ViewController and Views can't be linked to AppDelegate. It's like the app is split into two parts that can't communicate with each other.
Asked
Active
Viewed 91 times
-4
-
1Details matter. For instance, what do you mean by "state of the app"? What have you tried? Of course you can't call `AppDelegate` methods from a view controller! It's the way to communicate **from** the OS **to** the app! Having stated that - it's *your* app. And no, it isn't "split into two parts". Please, what are you *really* trying to do? (Details matter.) The `AppDelegate` is exactly what it says - the way your app can find out what the user is doing with the... "superapp" of your app - the OS. – Oct 23 '18 at 00:50
-
@dfd why are they in different places? what if what needs to be done is different depending on the screen? on android, lifecycle methods are activity specific. – livule Oct 23 '18 at 02:02
1 Answers
0
You can always using notifications...
Tutorial for listening to application moved to background:
override func viewDidLoad() {
super.viewDidLoad()
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(appMovedToBackground),
name: Notification.Name.UIApplicationWillResignActive, object: nil)
}
@objc func appMovedToBackground() {
print("App moved to background!")
}

Harsh
- 2,852
- 1
- 13
- 27