Hello. I solve this problem coding with "class let willDeactivateNotification: NSNotification.Name" for the screen background and coding "class let didActivateNotification: NSNotification.Name" for the screen foreground:
if #available(iOS 13.0, *) {
NotificationCenter.default.addObserver(self, selector: #selector(setDarkScreenObj), name: UIScene.willDeactivateNotification, object: nil)
}else {
NotificationCenter.default.addObserver(forName: UIApplication.didEnterBackgroundNotification, object: nil, queue: nil) { (notification) in
self.setDarkScreen()
}
}
if #available(iOS 13.0, *) {
NotificationCenter.default.addObserver(self, selector: #selector(setLightScreeenObj), name: UIScene.didActivateNotification , object: nil)
}else {
NotificationCenter.default.addObserver(forName:UIApplication.willEnterForegroundNotification, object: nil, queue: nil) {
(notification) in
self.setLightScreeen()
}
}
Reference: https://developer.apple.com/documentation/uikit/uiscene/3197922-didenterbackgroundnotification