swift中获取(判断)设备版本的方法

前端之家收集整理的这篇文章主要介绍了swift中获取(判断)设备版本的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.直接获取,按需要加if判断即可

        UIDevice.currentDevice().systemVersion as NSString).floatValue



2.获取每一位的版本号,利用switch进行判断

        let os = NSProcessInfo().operatingSystemVersion
        switch (os.majorVersion,os.minorVersion,os.patchVersion)
        {
        case (8,_,_):
            println("iOS >= 8.0.0")
        case (7,_):
            println("iOS >= 7.0.0,= 7.1.0,< 8.0.0")
        default:
            println("iOS = 8.0")
        }


3.获取版本号后,定义一个返回比较结果的对象进行比较

        let version = UIDevice.currentDevice().systemVersion
        /*
        进行比较 返回结果为 NSComparisonResult 其中,NSComparisonResult有三个值:
        case OrderedAscending// 小于被比较的值case OrderedSame//等于被比较的值case OrderedDescending//大于被比较的值
        */
        let flag = version.compare("8.0.0",options: NSStringCompareOptions.NumericSearch)
        //如果版本号<8.0.0
        if flag == .OrderedAscending
        {
        }
        else
        {
        }
原文链接:https://www.f2er.com/swift/326047.html

猜你在找的Swift相关文章