Created
September 5, 2019 08:05
-
-
Save MainasuK/71a5dc94c5d91b436485a3920b925392 to your computer and use it in GitHub Desktop.
AppDelegate for iOS 13 with multiple windows supports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
// Set up application here | |
if #available(iOS 13, *) { | |
} else { | |
window = UIWindow(frame: UIScreen.main.bounds) | |
window?.rootViewController = ViewController() | |
window?.makeKeyAndVisible() | |
} | |
return true | |
} | |
} | |
@available(iOS 13.0, *) | |
extension AppDelegate { | |
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { | |
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) | |
} | |
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<key>UIApplicationSceneManifest</key> | |
<dict> | |
<key>UISceneConfigurations</key> | |
<dict> | |
<key>UIWindowSceneSessionRoleApplication</key> | |
<array> | |
<dict> | |
<key>UISceneDelegateClassName</key> | |
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string> | |
<key>UISceneConfigurationName</key> | |
<string>Default Configuration</string> | |
<key>UISceneStoryboardFile</key> | |
<string>Main</string> | |
</dict> | |
</array> | |
</dict> | |
<key>UIApplicationSupportsMultipleScenes</key> | |
<true/> | |
</dict> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@available(iOS 13.0, *) | |
final class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var window: UIWindow? | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | |
if let userActivity = connectionOptions.userActivities.first ?? session.stateRestorationActivity { | |
configure(window: window, with: userActivity) | |
} | |
guard let windowScene = scene as? UIWindowScene else { | |
return | |
} | |
window = UIWindow(windowScene: windowScene) | |
window?.makeKeyAndVisible() | |
Coordinator.main.present(scene: .main(message: nil, window: window!), from: nil, completion: { | |
guard let url = connectionOptions.urlContexts.first?.url else { | |
return | |
} | |
// … | |
}) | |
} | |
func stateRestorationActivity(for scene: UIScene) -> NSUserActivity? { | |
return scene.userActivity | |
} | |
} | |
@available(iOS 13.0, *) | |
extension SceneDelegate { | |
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { | |
guard let url = URLContexts.first?.url else { | |
return | |
} | |
_ = Coordinator.main.handleUrl(UIApplication.shared, open: url) | |
} | |
} | |
@available(iOS 13.0, *) | |
extension SceneDelegate { | |
private func configure(window: UIWindow?, with userActivity: NSUserActivity) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment