Is it possible to opt-out of dark mode on iOS 13?

SeanR picture SeanR · Jun 11, 2019 · Viewed 130.4k times · Source

A large part of my app consists of web views to provide functionality not yet available through native implementations. The web team has no plans to implement a dark theme for the website. As such, my app will look a bit half/half with Dark Mode support on iOS 13.

Is it possible to opt out of Dark Mode support such that our app always shows light mode to match the website theme?

Answer

CodeBender picture CodeBender · Jun 11, 2019

First, here is Apple's entry related to opting out of dark mode. The content at this link is written for Xcode 11 & iOS 13:

This section applies to Xcode 11 usage


If you wish to opt out your ENTIRE application

Approach #1

Use the following key in your info.plist file:

UIUserInterfaceStyle

And assign it a value of Light.

The XML for the UIUserInterfaceStyle assignment:

<key>UIUserInterfaceStyle</key>
<string>Light</string>

Approach #2

You can set overrideUserInterfaceStyle against the app's window variable.

Depending on how your project was created, this may be in the AppDelegate file or the SceneDelegate.

if #available(iOS 13.0, *) {
    window?.overrideUserInterfaceStyle = .light
}


If you wish to opt out your UIViewController on an individual basis

override func viewDidLoad() {
    super.viewDidLoad()
    // overrideUserInterfaceStyle is available with iOS 13
    if #available(iOS 13.0, *) {
        // Always adopt a light interface style.
        overrideUserInterfaceStyle = .light
    }
}

Apple documentation for overrideUserInterfaceStyle

How the above code will look in Xcode 11:

enter image description here

This section applies to Xcode 10.x usage


If you are using Xcode 11 for your submission, you can safely ignore everything below this line.

Since the relevant API does not exist in iOS 12, you will get errors when attempting to use the values provided above:

For setting overrideUserInterfaceStyle in your UIViewController

enter image description here

If you wish to opt out your UIViewController on an individual basis

This can be handled in Xcode 10 by testing the compiler version and the iOS version:

#if compiler(>=5.1)
if #available(iOS 13.0, *) {
    // Always adopt a light interface style.
    overrideUserInterfaceStyle = .light
}
#endif

If you wish to opt out your ENTIRE application

You can modify the above snippet to work against the entire application for Xcode 10, by adding the following code to your AppDelegate file.

#if compiler(>=5.1)
if #available(iOS 13.0, *) {
    // Always adopt a light interface style.
    window?.overrideUserInterfaceStyle = .light
}
#endif

However, the plist setting will fail when using Xcode version 10.x:

enter image description here

Credit to @Aron Nelson, @Raimundas Sakalauskas, @NSLeader and rmaddy for improving this answer with their feedback.