How to check iOS version?

后端 未结 30 2428
一生所求
一生所求 2020-11-21 06:37

I want to check if the iOS version of the device is greater than 3.1.3 I tried things like:

[[UIDevice currentDevice].systemVersion         


        
30条回答
  •  执念已碎
    2020-11-21 07:07

    This is used to check for compatible SDK version in Xcode, this is if you have a large team with different versions of Xcode or multiple projects supporting different SDKs that share the same code:

    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
      //programming in iOS 8+ SDK here
    #else
      //programming in lower than iOS 8 here   
    #endif
    

    What you really want is to check the iOS version on the device. You can do that with this:

    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
      //older than iOS 8 code here
    } else {
      //iOS 8 specific code here
    }
    

    Swift version:

    if let version = Float(UIDevice.current.systemVersion), version < 9.3 {
        //add lower than 9.3 code here
    } else {
        //add 9.3 and above code here
    }
    

    Current versions of swift should be using this:

    if #available(iOS 12, *) {
        //iOS 12 specific code here
    } else {
        //older than iOS 12 code here
    }
    

提交回复
热议问题