How to differentiate code based on iOS version during compile time

165 views Asked by At

I have been using 'UIKit.UIUserInterfaceStyle UIKit.UITraitCollection::get_UserInterfaceStyle()' API for iOS version 12+. I need to compile the source on iOS version version 9+, I need to differentiate the usage of above API using Conditional compilation. Is there any possibilities to get it done.

1

There are 1 answers

0
nevermore On

You can check the device version at runtime and choose whether to use the APi or not:

if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
{
    //use api in iOS 12
}
else
{
    //...
}