How to check iOS version?

后端 未结 30 2477
一生所求
一生所求 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:21

    UIDevice+IOSVersion.h

    @interface UIDevice (IOSVersion)
    
    + (BOOL)isCurrentIOSVersionEqualToVersion:(NSString *)iOSVersion;
    + (BOOL)isCurrentIOSVersionGreaterThanVersion:(NSString *)iOSVersion;
    + (BOOL)isCurrentIOSVersionGreaterThanOrEqualToVersion:(NSString *)iOSVersion;
    + (BOOL)isCurrentIOSVersionLessThanVersion:(NSString *)iOSVersion;
    + (BOOL)isCurrentIOSVersionLessThanOrEqualToVersion:(NSString *)iOSVersion
    
    @end
    

    UIDevice+IOSVersion.m

    #import "UIDevice+IOSVersion.h"
    
    @implementation UIDevice (IOSVersion)
    
    + (BOOL)isCurrentIOSVersionEqualToVersion:(NSString *)iOSVersion
    {
        return [[[UIDevice currentDevice] systemVersion] compare:iOSVersion options:NSNumericSearch] == NSOrderedSame;
    }
    
    + (BOOL)isCurrentIOSVersionGreaterThanVersion:(NSString *)iOSVersion
    {
        return [[[UIDevice currentDevice] systemVersion] compare:iOSVersion options:NSNumericSearch] == NSOrderedDescending;
    }
    
    + (BOOL)isCurrentIOSVersionGreaterThanOrEqualToVersion:(NSString *)iOSVersion
    {
        return [[[UIDevice currentDevice] systemVersion] compare:iOSVersion options:NSNumericSearch] != NSOrderedAscending;
    }
    
    + (BOOL)isCurrentIOSVersionLessThanVersion:(NSString *)iOSVersion
    {
        return [[[UIDevice currentDevice] systemVersion] compare:iOSVersion options:NSNumericSearch] == NSOrderedAscending;
    }
    
    + (BOOL)isCurrentIOSVersionLessThanOrEqualToVersion:(NSString *)iOSVersion
    {
        return [[[UIDevice currentDevice] systemVersion] compare:iOSVersion options:NSNumericSearch] != NSOrderedDescending;
    }
    
    @end
    

提交回复
热议问题