3

I was trying to init var window: UIWindow? to a UIViewController programmatically in AppDelegate.But I cannot achieve it. When I was updated my Xcode to Version 11.0 (11A420a), in project init section, I choosed to with Storyboard not to SwiftUI but I can not achieved to programmatically assign the UIWindow's rootViewController to a view controller. So first of all, I removed the Main.storyboard file, then I hang with Info.plist and removed the storyboard section as usual like I do before but there's some configs about UIApplicationSceneManifest as shown below. And

<key>UIApplicationSceneManifest</key> <dict> <key>UIApplicationSupportsMultipleScenes</key> <false/> <key>UISceneConfigurations</key> <dict> <key>UIWindowSceneSessionRoleApplication</key> <array> <dict> <key>UISceneConfigurationName</key> <string>Default Configuration</string> <key>UISceneDelegateClassName</key> <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string> </dict> </array> </dict> </dict> 

By the way, for checking out what happens, I tried the init window in SceneDelegate.swift and AppDelegate.swift file but simulator's screen shows black screen fully. So what I must to do?

Hint: var window: UIWindow! variable description is not added to AppDelegate default anymore, its in SceneDelegate. So can I set my rootViewController from SceneDelegate file?

What's the way to achieve fully programmatically this in the new AppDelegate/SceneDelegate approach?

4
  • You need to learn and embrace the new scene architecture of iOS 13. Start in the documentation with Scenes. Commented Sep 24, 2019 at 0:14
  • 1
    Then get some popcorn and go to WWDC 2019 Video and watch videos 808, 212, 224, 258, and 259. Commented Sep 24, 2019 at 0:19
  • @rmaddy I will watch these, what do you recommend for drinks :) ? Commented Sep 24, 2019 at 13:36
  • 1
    For anyone looking for an updated "Single View App" Xcode template that supports iOS 12 and 13 as well as supporting either a storyboard or an all-code user interface, see github.com/rmaddy/XcodeTemplates. Commented Sep 25, 2019 at 5:31

1 Answer 1

1

In AppDelegate I removed the lines which contains functions of UISceneSession Lifecyle then it worked it.

// MARK: UISceneSession Lifecycle func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } 

Than add var window: UIWindow? property to AppDelegate and inited it and set rootViewController programmatically, then worked it but for detail information, I will edit my answer as soon as I learned about UIScene workflow.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.