iOS 判断系统版本

方案一

double systemVersion = [UIDevice currentDevice].systemVersion.boolValue;

    if (systemVersion >= 7.0) {
        // >= iOS 7.0
    } else {
        // < iOS 7.0
    }

    if (systemVersion >= 10.0) {
        // >= iOS 10.0
    } else {
        // < iOS 10.0
    }

如果只是大致判断是哪个系统版本,上面的方法是可行的,如果具体到某个版本,如 10.0.1,那就会有偏差。我们知道systemVersion依旧是10.0。

方案二

    NSString *systemVersion = [UIDevice currentDevice].systemVersion;
    NSComparisonResult comparisonResult = [systemVersion compare:@"10.0.1" options:NSNumericSearch];

    if (comparisonResult == NSOrderedAscending) {
        // < iOS 10.0.1
    } else if (comparisonResult == NSOrderedSame) {
        // = iOS 10.0.1
    } else if (comparisonResult == NSOrderedDescending) {
        // > iOS 10.0.1
    }

    或者

    if (comparisonResult != NSOrderedAscending) {
        // >= iOS 10.0.1
    } else {
        // < iOS 10.0.1
    }

有篇博客提到,这种方法不靠谱。比如系统版本是10.1.1,而我们提供的版本是8.2,会返回NSOrderedAscending,即认为10.1.1 < 8.2 。
其实,用这样的比较方式NSComparisonResult comparisonResult = [systemVersion compare:@"10.0.1"],的确会出现这种情况࿰

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值