Check iOS version at runtime?

前端 未结 11 1225
-上瘾入骨i
-上瘾入骨i 2020-12-01 03:03

This is sort of a follow on from my last question. I am using beginAnimations:context: to setup an animation block to animate some UITextLabels. However I notic

11条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 03:32

    Most of these solutions on here are so overkill. All you need to do is [[UIDevice currentDevice].systemVersion intValue]. This automatically removes the decimal, so there is no need to split the string.

    So you can just check it like:

    if ([[UIDevice currentDevice].systemVersion intValue] >= 8) {
        // iOS 8.0 and above
    } else {
        // Anything less than iOS 8.0
    }
    

    You can also define a macro with this code:

    #define IOS_VERSION [[UIDevice currentDevice].systemVersion intValue];
    

    or even include your check:

    #define IOS_8PLUS ([[UIDevice currentDevice].systemVersion intValue] >= 8)
    

    Then you just need to do:

    if (IOS_8PLUS) {
        // iOS 8.0 and above
    } else {
        // Anything less than iOS 8.0
    }
    

提交回复
热议问题