Skip to content

Instantly share code, notes, and snippets.

@DnV1eX
Created July 25, 2020 03:29
Show Gist options
  • Save DnV1eX/f6bf0fddb27f4db9013bdae56cfa8786 to your computer and use it in GitHub Desktop.
Save DnV1eX/f6bf0fddb27f4db9013bdae56cfa8786 to your computer and use it in GitHub Desktop.
Restore calling UIApplicationDelegate methods on UIApplication state change when using UIWindowSceneDelegate.
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func sceneWillResignActive(_ scene: UIScene) {
if !UIApplication.shared.connectedScenes.contains(where: { $0.activationState == .foregroundActive && $0 != scene }) {
UIApplication.shared.delegate?.applicationWillResignActive?(.shared)
}
}
func sceneDidEnterBackground(_ scene: UIScene) {
if !UIApplication.shared.connectedScenes.contains(where: { $0.activationState == .foregroundActive || $0.activationState == .foregroundInactive }) {
UIApplication.shared.delegate?.applicationDidEnterBackground?(.shared)
}
}
func sceneWillEnterForeground(_ scene: UIScene) {
if !UIApplication.shared.connectedScenes.contains(where: { $0.activationState == .foregroundActive || $0.activationState == .foregroundInactive }) {
UIApplication.shared.delegate?.applicationWillEnterForeground?(.shared)
}
}
func sceneDidBecomeActive(_ scene: UIScene) {
if !UIApplication.shared.connectedScenes.contains(where: { $0.activationState == .foregroundActive && $0 != scene }) {
UIApplication.shared.delegate?.applicationDidBecomeActive?(.shared)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment