1

So iOS 13 is really causing trouble for me! I cant get my head around how the SceneDelegate can be uses within my existing application.

Currently I'm using a boolean check in my AppDelegate to determine which ViewController is presented first.. I need to figure out how to replicate this using the SceneDelegate.

My main concern is how can I ensure my app will work on both iOS 13 and any iOS version before? If I add the SceneDelegate won't it crash my app running on pre iOS 13?

Here is my current method of setting the rootVC

if (loggedIn == nil){
           Utilities.setLoginAsInitialViewContoller(window: window)
       }
       else
       {
           if(termsAgree == nil){
               Utilities.setTermsAsInitialViewController(window: window)
           }
           if(loggedIn != nil){
               if(termsAgree != nil){
                   Utilities.setHomeAsInitialViewContoller(window: window)
               }
           }
       }
class func setLoginAsInitialViewContoller(window:UIWindow) {
       let storyboard = UIStoryboard(name: “Login”, bundle: nil)
       let controller = storyboard.instantiateViewController(withIdentifier: “LoginViewController”)
       window.rootViewController = controller
       window.makeKeyAndVisible()
   }
   class func setHomeAsInitialViewContoller(window:UIWindow) {
       let storyboard = UIStoryboard(name: “Home”, bundle: nil)
       let controller = storyboard.instantiateViewController(withIdentifier: “MainViewNavController”)
       window.rootViewController = controller
       window.makeKeyAndVisible()
   }
   class func setTermsAsInitialViewController(window:UIWindow){
       let storyboard = UIStoryboard(name: “Terms”, bundle: nil)
       let controller = storyboard.instantiateViewController(withIdentifier: “TermsViewController”)
       window.rootViewController = controller
       window.makeKeyAndVisible()
   }

The above code is contained in my Utilities.swift class and is called in my AppDelegate.swift like this:

Utilities.decideInitialViewController(window: self.window!)
1
  • Did you find solution for this problem?
    – ShadeToD
    Commented Mar 24, 2020 at 10:25

1 Answer 1

1

You cannot use the SceneDelegate pre iOS 13, this will actually lead to a compilation error.

xxx is only available in iOS 13.0 or newer

All existing app doesn't require the SceneDelegate to be compatible with iOS 13.

You can just build your application with the latest Xcode version, and you should be good to go (with few adjustments, like dark mode compatibility and some new UI changes, but this won't prevent your app from running in an iOS 13+ device).

Even if I would not recommend that, you still can use the SceneDelegate, but you must use the @available tag to tell Xcode that this code will only be used for iOS 13+ devices. This means that iOS 13+ devices will use the SceneDelegate, and iOS 12 and less, will continue to use the AppDelegate. This method require to maintain some backward compatibility only code.

There is some explanation on that here