Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my iOS app disable dark mode?

So ... I've tried to set my app to disable iOS 13 dark mode by forcing light mode according apple documentation, in the emulator all attempts work fine, but when I try on the real device, nothing happens, it's like I've never changed my code

First Attempt

Override the Interface Style for a Window, View, or View Controller

I tried to put this code sample in my viewDidLoad()

Nothing Changed

if #available(iOS 13.0, *) {
   overrideUserInterfaceStyle = .light
} else {
  // Fallback on earlier versions
}

Second Attempt

Opt Out of Dark Mode Entirely

The system automatically opts in any app linked against the iOS 13.0 or later SDK to both light and dark appearances. If you need extra time to work on your app's Dark Mode support, you can temporarily opt out by including the UIUserInterfaceStyle key (with a value of Light) in your app’s Info.plist file. Setting this key to Light causes the system to ignore the user's preference and always apply a light appearance to your app.

Nothing changed

Apple Documentation: Choosing a Specific Interface Style for Your iOS App

If anyone knows how I set my app only in light mode... I'll be very grateful :D

like image 787
Fogaiht Avatar asked Oct 29 '19 14:10

Fogaiht


People also ask

Why can't I turn dark mode off?

On AndroidGo to Settings. Then, tap on Theme. You can either choose System Default or Light. Select Light to eliminate the Dark mode.

Can you turn off dark mode for certain apps iPhone?

On the New Automation screen, scroll down and tap the “App” option. Tap on “Choose” and select all the apps for which you want to override the dark mode. Hit Done.

Why can't I get dark mode off my iPhone?

Step 1: Open the “Settings” app on your device. Step 2: After that, click “Display & Brightness”. Step 3: Here, you will see the icons for “Light” and “Dark” Mode. So, click “Dark” to turn to Dark mode and that's all.

How do I force an app to dark out?

Open System Settings. Navigate to Developer Options. Scroll down the Hardware accelerated rendering section and enable the Override force-dark/Force dark mode* option.


2 Answers

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

Should work. Call it in your AppDelegate's didFinishLaunchingWithOptions.

like image 125
ChrisTheGreat Avatar answered Oct 20 '22 13:10

ChrisTheGreat


Simply you can add a new key UIUserInterfaceStyle in your app info.plist (Notes: Xcode 12 and above has renamed to Appearance) and set its value to Light or Dark. this will override the app default style to the value you provide.

so you don't need to bother about having it anywhere else

like image 10
Reed Avatar answered Oct 20 '22 14:10

Reed