Maintain Compatibility with iOS11 in 2020

It CAN be done

Image for post
Image for post

Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 11.4.1, and Swift 5.2.2

I’m going to get rid of the Storyboard as I work like that here's how to do it. Sorry.

I’m going to have an initial view controller that just displays an image of Golshifteh Farahani. Sorry for lack of originality.

We are going to need to launch the InitialViewController. This reqyures replacing

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
}

with

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) 
{ guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene self.window ?.rootViewController = InitialViewController() window?.makeKeyAndVisible() }

but of course we will also need an instance variable to hold the reference for the window.

But what about iOS11?

Image for post
Image for post

If we change the deployment target in the project

which then allows you to choose iOS11 simulators (as long as you have them added in Xcode.

Then…

Image for post
Image for post

So we need to work through the App delegate!

We are going ahead to fix those errors.

We add a property for UIWindow:

and change the func application(application: didFinishLaunchingWithOptions:) -> Bool function to

Fix the SceneDelegate We only wish to use the SceneDelegate if it is avaliable, so we can put the following statement@available(iOS 13.0, *) just above the SceneDelegate class declaration.

Image for post
Image for post

Now this works on iOS11 devices!

It is rather complex in the description, but rather easy in the implementation. Take a look at the attached Repo. It is a rather wonderful thing.

If you’ve any questions, comments or suggestions please hit me up on Twitter

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store