'Disable dark mode on iOS app while still being able to get prefers-color-scheme from WKWebView
I'm using the newest version on Xcode for my iOS app.
I don't want iOS to automatically change the colors in my app when device is in dark mode, because it doesn't look good and also isn't necessary.
Therefore, I added the following in the Info.plist file:
<key>UIUserInterfaceStyle</key>
<string>Light</string>
This will always keep the app in light mode, no matter if user has turned on the dark mode or not.
I also have a WKWebView in my app. I want to be able to detect if the dark mode is turned on to provide the appropriate CSS. This is possible with the following CSS code:
<style>
@media (prefers-color-scheme: dark) {
body {
background-color: black;
}
}
</style>
In this case, the html's body will be black, but only if the iOS device is in dark mode.
BUT: This CSS snippet doesn't work if I force light mode for my app in Info.plist with UIUserInterfaceStyle.
So, either I remove UIUserInterfaceStyle from Info.plist file or I won't be able to detect dark mode via CSS in WKWebView.
Or, is there a way to prevent iOS to automatically adjust colors in dark mode while I'm still able to detect via CSS loaded in the WKWebView if dark mode is enabled?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
