Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opt out of UISceneDelegate/SwiftUI on iOS

People also ask

Does iOS 13 support SwiftUI?

SwiftUI runs on iOS 13, macOS 10.15, tvOS 13, and watchOS 6, or any future later versions of those platforms. This means if you work on an app that must support iOS N-1 or even N-2 – i.e., the current version and one or two before that – then you will be limited in terms of the features you can offer.


While you should embrace using scenes when your app is run under iOS 13 and later, you can fully opt out while you still support iOS 12 or earlier.

  • Completely remove the “Application Scene Manifest” entry from Info.plist.

  • If there is a scene delegate class, remove it.

  • If there are any scene related methods in your app delegate, remove those methods.

  • If missing, add the property var window: UIWindow? to your app delegate.

Your app should now only use the app delegate and under iOS 13 it should have the same life cycle as iOS 12.

Note: None of this is specific to Swift or SwiftUI.


This is something I faced also, and there's a few scenarios at play here:

  • If you want to work on an existing UIKit app in Xcode 11, simply open it up and it should work fine. All my apps have, with no SceneDelegate file nor any changes to AppDelegate or storyboards.
  • If you want to create a new UIKIT app targeting iOS 13, simply create it while making sure you leave the "Use SwiftUI" checkbox unchecked.

But I'm wondering if you are facing the third scenario - one that I did about a week ago. Creating a new `UIKit app targeting something earlier than iOS 13. (I actually targeted iOS 9!)

Yep, your template will give you 15 errors (as of beta 5), along with a SceneDelegate file/class. Fortunately, Xcode will help you auto-correct all but one.

The last one is to add one line that is part of the SceneDelegate class but unfortunately Apple left it out of the AppDelegate class - which after more than a dozen @available(iOS 13.0, *) clauses means you've opted out of SceneDelegate if running iOS 12 and guess what? It's not there in ApDelegate!

Add this to your AppDelegate:

var window: UIWindow?

At that point, your should have a running UIKit app targeted for iOS 12 and earlier.


I got this to work using dfd's answer, but because my app is in Objective-C, I had to make one change:

In Objective-C, you want to put

@property (strong, nonatomic) UIWindow *window;

in AppDelegate.h (not in the .m)


Okay so I figured it out. Due to the changes in iOS 13 of Apple's new default card presentation style, in my storyboard segue from my splash screen to my custom flow navigation controller defaulted to the new presentation (see screenshot below).

Segue

How I fixed that was to go back to the old style which defaulted to the old lifecycle. See screenshot below.

Storyboard seque kind

Not sure why it did, as this was the only place in my application that caused this (pretty big app so I have to spend some time going through all the storyboards to make sure).


Xcode 12 - Swift 5.3 - iOS 14

Since Xcode 12 and with the help of Swift 5.3 and @main, you can have a multiplatform app that has no SceneDelegate or event AppDelegate. There will be only a simple file like:

import SwiftUI

@main
struct MyMultiPlatformApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}