How to check iOS version?

后端 未结 30 2415
一生所求
一生所求 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 06:58

    Starting Xcode 9, in Objective-C:

    if (@available(iOS 11, *)) {
        // iOS 11 (or newer) ObjC code
    } else {
        // iOS 10 or older code
    }
    

    Starting Xcode 7, in Swift:

    if #available(iOS 11, *) {
        // iOS 11 (or newer) Swift code
    } else {
        // iOS 10 or older code
    }
    

    For the version, you can specify the MAJOR, the MINOR or the PATCH (see http://semver.org/ for definitions). Examples:

    • iOS 11 and iOS 11.0 are the same minimal version
    • iOS 10, iOS 10.3, iOS 10.3.1 are different minimal versions

    You can input values for any of those systems:

    • iOS, macOS, watchOS, tvOS

    Real case example taken from one of my pods:

    if #available(iOS 10.0, tvOS 10.0, *) {
        // iOS 10+ and tvOS 10+ Swift code
    } else {
        // iOS 9 and tvOS 9 older code
    }
    

    documentation

提交回复
热议问题