Set rootViewController iOS 13
This is because AppDelegate doesn't have window
property anymore.
Now you must use SceneDelegate's scene(_:willConnectTo:options:)
method to change root view controller.
Like shown in this example:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let scene = (scene as? UIWindowScene) else { return }
// Instantiate UIWindow with scene
let window = UIWindow(windowScene: scene)
// Assign window to SceneDelegate window property
self.window = window
// Set initial view controller from Main storyboard as root view controller of UIWindow
self.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
// Present window to screen
self.window?.makeKeyAndVisible()
}
Update root view controller after user login + iOS 13 and later
This is how I managed navigation for both the older version and the new version. So when the user has the latest iOS we need to setup root from sceneDelegate
and for older version we need to setup root from appDelegate
AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 13, *) {
} else {
setupRoot()
}
return true
}
// MARK: UISceneSession Lifecycle
@available(iOS 13.0, *)
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
@available(iOS 13.0, *)
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}
func setupRoot() {
//Setup Your Root Here
//window?.rootViewController = objNavigationVC
//window?.makeKeyAndVisible()
}
}
SceneDelegate.swift
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window = window
appDelegate.setupRoot()
}
}
How to set root view controller programmatically in Xcode 13 with SpriteKit?
If you want to delete the Main.Storyboard, you need to add the following to your AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
let viewController = GameViewController()
window?.rootViewController = viewController
window?.makeKeyAndVisible()
return true
}
And in GameViewController.swift you need to add the following:
override func loadView() {
self.view = SKView(frame: UIScreen.main.bounds)
}
Related Topics
The Sandbox Is Not in Sync with the Podfile.Lock-Ios
Locationmanager:Didenterregion Not Called When a Beacon Is Detected
Present a Modal View Controller with Transparent Background
Getting Data from Each Uitableview Cells Swift
Get Error Code -11843 While Exporting Mp3 File in Ipod Library Since iOS 5.1
Nsurlsessiondatatask Datataskwithurl Completion Handler Not Getting Called
Flutter: Cocoapods's Specs Repository Is Too Out-Of-Date to Satisfy Dependencies
How to Set Cornerradius for Only Bottom-Left,Bottom-Right and Top-Left Corner of a Uiview
Change Tab Bar Tint Color on iOS 7
How to Position Views on Top of Each Other
Ios13 Share Sheet: How to Set Preview Thumbnail When Sharing Uiimage
iPhone Storage in Tmp Directory
Get Dns Server Ip from iPhone Settings