【Swift】获取设备信息

//MARK: -  获取设备类型
//deviceType设备类型获取地址https://www.theiphonewiki.com/wiki/Models

 func getDeviceVersion(){
        var systemInfo = utsname()
        uname(&systemInfo)

        let deviceString = withUnsafePointer(&systemInfo.machine) { (ASCIIChar) -> String in

            return String.fromCString(UnsafePointer(ASCIIChar))!

        }
        let deviceType = ["iPhone1,1" :  "iPhone",
            "iPhone1,2" :  "iPhone3G",
            "iPhone2,1" :  "iPhone3GS",
            "iPhone3,1" :  "iPhone4",
            "iPhone3,2" :  "iPhone4",
            "iPhone3,3" :  "iPhone4",
            "iPhone4,1" :  "iPhone4S",
            "iPhone5,1" :  "iPhone5",
            "iPhone5,2" :  "iPhone5",
            "iPhone5,3" :  "iPhone5C",
            "iPhone5,4" :  "iPhone5C",
            "iPhone6,1" :  "iPhone5S",
            "iPhone6,2" :  "iPhone5S",
            "iPhone7,2" :  "iPhone6",
            "iPhone7,1" :  "iPhone6 Plus",
            "iPhone8,1" :  "iPhone6s",
            "iPhone8,2" :  "iPhone6s Plus",
            "iPhone8,4" :  "iPhone5SE",
            "iPod1,1"   :  "iPod touch",
            "iPod2,1"   :  "iPod touch 2G",
            "iPod3,1"   :  "iPod touch 3G",
            "iPod4,1"   :  "iPod touch 4G",
            "iPod5,1"   :  "iPod touch 5G",
            "iPad1,1"   :  "iPad1",
            "iPad2,1"   :  "iPad2",
            "iPad2,2"   :  "iPad2",
            "iPad2,3"   :  "iPad2",
            "iPad2,4"   :  "iPad2",
            "iPad3,1"   :  "iPad3",
            "iPad3,2"   :  "iPad3",
            "iPad3,3"   :  "iPad3",
            "iPad3,4"   :  "iPad4",
            "iPad3,5"   :  "iPad4",
            "iPad3,6"   :  "iPad4",
            "iPad4,1"   :  "iPad Air",
            "iPad4,2"   :  "iPad Air",
            "iPad4,3"   :  "iPad Air",
            "iPad5,3"   :  "iPad Air 2",
            "iPad5,4"   :  "iPad Air 2",
            "iPad2,5"   :  "iPad mini 1G",
            "iPad2,6"   :  "iPad mini 1G",
            "iPad2,7"   :  "iPad mini 1G",
            "iPad4,4"   :  "iPad mini 2",
            "iPad4,5"   :  "iPad mini 2",
            "iPad4,6"   :  "iPad mini 2",
            "iPad4,7"   :  "iPad mini 3",
            "iPad4,8"   :  "iPad mini 3",
            "iPad4,9"   :  "iPad mini 3",
            "iPad6,7"   :  "iPad Pro",
            "iPad6,8"   :  "iPad Pro",
            "iPad6,3"   :  "iPad Pro",
            "iPad6,4"   :  "iPad Pro",]

        if let deviceTypeString = deviceType[deviceString]{

            print("===\(deviceTypeString)")

        }


    }


你可能感兴趣的:(Swift)