overrideUserInterfaceStyle not working in AppDelegate

583 views Asked by At

I'm building an iOS app with the newest version of Xcode.

If I set

overrideUserInterfaceStyle = .light

to a View Controller, it will get set to light mode, also if dark mode is enabled.

But If I put this code in AppDelegate like this:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
    window?.overrideUserInterfaceStyle = .light
    
    return true
}

it doesn't work.

There are no errors. The app simply is in light mode or dark mode depending on the mode the device is in.

Why doesn't overrideUserInterfaceStyle work in AppDelegate? Is it because I'm using a Tab Bar Controller for my app? I don't think so.

1

There are 1 answers

0
Mirko On

It's too early to call overrideUserInterfaceStyle in AppDelegate, window is not yet created. You can use SceneDelegate willConnectTo function.