I just dealt with this myself, and here's the part that bit me:
In your step 5... It's possible for a user to register for an account with you entirely separate from their Facebook ID, right? Then some other time they log in with Facebook.... And you just created them a second account and lost their first one.
There needs to be a way to be logged in to your web service, then log in to facebook, and capture the association between the facebook ID and the local account.
Apart from that, your plan sounds solid.
Update: Facebook has added a doc outlining such a scenario HERE
Swift 5:
traitCollectionDidChange also gets called a few times. This is how I detect DarkMode runtime change and setColors().
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
setColors()
}
In setColors() func I update the colors.
Detecting current colorScheme:
extension UIViewController {
var isDarkMode: Bool {
if #available(iOS 13.0, *) {
return self.traitCollection.userInterfaceStyle == .dark
}
else {
return false
}
}
}
I have colors defined like this (for iOS < 13):
enum ColorCompatibility {
static var myOlderiOSCompatibleColorName: UIColor {
if UIViewController().isDarkMode {
return UIColor(red: 33, green: 35, blue: 37, alpha: 0.85)
}
else {
return UIColor(hexString: "#F3F3F3", alpha: 0.85)
}
}
}
Example:
private func setColors() {
myView.backgroundColor = ColorCompatibility.myOlderiOSCompatibleColorName
}
Also you might need to call setColors in ViewDidLoad/Will/DidAppear depending on your case like this:
viewDidLoad() {
...
setColors()
...
}
For iOS11+ you could use "named Colors", defined in Assets and much easier to use in IB.
Cheers
Best Answer
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:
Entire app via info.plist file (Xcode 12)
Use the following key in your info.plist file:
And assign it a value of
Light
.The XML for the
UIUserInterfaceStyle
assignment:Apple documentation for UIUserInterfaceStyle
Entire app via info.plist in build settings (Xcode 13)
Entire app window via window property
You can set
overrideUserInterfaceStyle
against the app'swindow
variable. This will apply to all views that appear within the window. This became available with iOS 13, so for apps that support previous versions, you must include an availability check.Depending on how your project was created, this may be in the
AppDelegate
orSceneDelegate
file.Individual UIViewController or UIView
You can set
overrideUserInterfaceStyle
against theUIViewController
s orUIView
'soverrideUserInterfaceStyle
variable. This became available with iOS 13, so for apps that support previous versions, you must include an availability check.When set against the
UIViewController
, the view controller and its children adopt the defined mode.When set against the
UIView
, the view and its children adopt the defined mode.Apple documentation for overrideUserInterfaceStyle
Individual views via SwiftUI View
You can set
preferredColorScheme
to be eitherlight
ordark
. The provided value will set the color scheme for the presentation.Apple documentation for preferredColorScheme
Credit to @Aron Nelson, @Raimundas Sakalauskas, @NSLeader and @rmaddy for improving this answer with their feedback.