如何在编译时基于iOS版本区分代码

问题描述 投票:-1回答:1

我一直在使用iOS 12以上版本的'UIKit.UIUserInterfaceStyle UIKit.UITraitCollection :: get_UserInterfaceStyle()'API。我需要在iOS版本9+上编译源代码,我需要使用条件编译来区分上述API的用法。有没有可能完成它。

ios xamarin xamarin.ios ios9
1个回答
0
投票

您可以在运行时检查设备版本并选择是否使用APi:

if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
{
    //use api in iOS 12
}
else
{
    //...
} 
© www.soinside.com 2019 - 2024. All rights reserved.