Handling Dark Mode for iOS 13 with the Service SDK - forcedotcom/ServiceSDK-iOS GitHub Wiki

If you’d like to take advantage of the dark mode support in iOS 13 when using the Service SDK, you can simply customize the SDK colors using updated UIColor objects that are capable of handling dark mode. This can be done using the asset catalog or programmatically. (To learn more, see Apple's documentation on Supporting Dark Mode in Your Interface.)

The following information provides some guidance on how to programmatically create colors that will work with dark mode.

Here's an example in Swift:

let lightColor = // your custom light color
let darkColor = // your custom dark color

var dynamicColor: UIColor {

    // If you support earlier versions, then check
    // the version before providing dynamic colors…
    if #available(iOS 13.0, *) {

        return UIColor {
            (traitCollection: UITraitCollection) -> UIColor in
                switch traitCollection.userInterfaceStyle {
                case .dark:
                    return darkColor
                default:
                    return lightColor
                }
        }

    // For older versions, just return the standard color
    } else {
        return lightColor
    }
}

And in Objective-C:

UIColor *lightColor = // your custom light color;
UIColor *darkColor = // your custom dark color;

UIColor *dynamicColor = nil;

// If you support earlier versions, then check
// the version before providing dynamic colors…
if (@available(iOS 13.0, *)) {
    dynamicColor = 
      [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
        UIColor *resolvedColor = light;
        switch (traitCollection.userInterfaceStyle) {
            case UIUserInterfaceStyleDark: {
                 resolvedColor = darkColor;
                 break;
             }
             default: {
                 resolvedColor = lightColor;
                 break;
             }
         }
         return resolvedColor;
    }];

// For older versions, just return the standard color
} else {
    dynamicColor = lightColor;
}

Then pass this dynamic color object to the SCAppearanceConfiguration object just as you would any other color. For example:

// Create appearance configuration instance
let appearance = SCAppearanceConfiguration()

// Customize color tokens using dynamic colors
appearance.setColor(dynamicColor, forName: .brandPrimary)
// ... customize other colors

// Save configuration instance
ServiceCloud.shared().appearanceConfiguration = appearance