贴代码:
static varmodelName:String{
varsystemInfo =utsname()
uname(&systemInfo)
letmachineMirror =Mirror(reflecting: systemInfo.machine)
letidentifier = machineMirror.children.reduce("") { identifier, elementin
guardletvalue = element.valueas?Int8, value !=0else{returnidentifier }
returnidentifier +String(UnicodeScalar(UInt8(value)))
}
switchidentifier {
case "iPhone1,1":
return"iPhone 2G"
case "iPhone1,2":
return"iPhone 3G"
case "iPhone2,1":
return"iPhone 3GS"
case "iPhone3,1", "iPhone3,2", "iPhone3,3": return "iPhone 4"
case"iPhone4,1": return"iPhone 4s"
case"iPhone5,1": return"iPhone 5"
case"iPhone5,2": return"iPhone 5 (GSM+CDMA)"
case"iPhone5,3": return"iPhone 5c (GSM)"
case"iPhone5,4": return"iPhone 5c (GSM+CDMA)"
case"iPhone6,1": return"iPhone 5s (GSM)"
case"iPhone6,2": return"iPhone 5s (GSM+CDMA)"
case"iPhone7,2": return"iPhone 6"
case"iPhone7,1": return"iPhone 6 Plus"
case"iPhone8,1": return"iPhone 6s"
case"iPhone8,2": return"iPhone 6s Plus"
case"iPhone8,4": return"iPhone SE"
case"iPhone9,1": return"国行、日版、港行iPhone 7"
case"iPhone9,2": return"港行、国行iPhone 7 Plus"
case"iPhone9,3": return"美版、台版iPhone 7"
case"iPhone9,4": return"美版、台版iPhone 7 Plus"
case"iPhone10,1","iPhone10,4": return"iPhone 8"
case"iPhone10,2","iPhone10,5": return"iPhone 8 Plus"
case"iPhone10,3","iPhone10,6": return"iPhone X"
case "iPhone11,2":
return"iPhone XS"
case "iPhone11,8":
return"iPhone XR"
case "iPhone11,4","iPhone11,6":
return "iPhone XSMax"
default:
return "Unknown iPhone"
}
}