Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Basic code to get the Hardware Model of an iOS device in Swift
func platform() -> String {
var size: UInt = 0
sysctlbyname("hw.machine", nil, &size, nil, 0)
var machine = [CChar](count: Int(size), repeatedValue: 0)
sysctlbyname("hw.machine", &machine, &size, nil, 0)
return String.fromCString(machine)!
}
func model() -> String {
let model = self.platform()
switch model {
case "iPhone1,1":
return "iPhone 1G"
case "iPhone1,2":
return "iPhone 3G"
case "iPhone2,1":
return "iPhone 3GS"
case "iPhone3,1":
return "iPhone 4"
case "iPhone3,3":
return "Verizon iPhone 4"
case "iPhone4,1":
return "iPhone 4S"
case "iPhone5,1":
return "iPhone 5 (GSM)"
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 "iPod1,1":
return "iPod Touch 1G"
case "iPod2,1":
return "iPod Touch 2G"
case "iPod3,1":
return "iPod Touch 3G"
case "iPod4,1":
return "iPod Touch 4G"
case "iPod5,1":
return "iPod Touch 5G"
case "iPad1,1":
return "iPad"
case "iPad2,1":
return "iPad 2 (WiFi)"
case "iPad2,2":
return "iPad 2 (GSM)"
case "iPad2,3":
return "iPad 2 (CDMA)"
case "iPad2,4":
return "iPad 2 (WiFi)"
case "iPad2,5":
return "iPad Mini (WiFi)"
case "iPad2,6":
return"iPad Mini (GSM)"
case "iPad2,7":
return "iPad Mini (GSM+CDMA)"
case "iPad3,1":
return "iPad 3 (WiFi)"
case "iPad3,2":
return "iPad 3 (GSM+CDMA)"
case "iPad3,3":
return "iPad 3 (GSM)"
case "iPad3,4":
return "iPad 4 (WiFi)"
case "iPad3,5":
return "iPad 4 (GSM)"
case "iPad3,6":
"iPad 4 (GSM+CDMA)"
case "iPad4,1":
return "iPad Air (WiFi)"
case "iPad4,2":
return "iPad Air (Cellular)"
case "iPad4,3":
return"iPad Air"
case "iPad4,4":
return "iPad Mini 2G (WiFi)"
case "iPad4,5":
return "iPad Mini 2G (Cellular)"
case "iPad4,6":
return "iPad Mini 2G"
case "iPad4,7":
return "iPad Mini 3 (WiFi)"
case "iPad4,8":
return "iPad Mini 3 (Cellular)"
case "iPad4,9":
return "iPad Mini 3 (China)"
case "iPad5,3":
return "iPad Air 2 (WiFi)"
case "iPad5,4":
return "iPad Air 2 (Cellular)"
case "AppleTV2,1":
return "Apple TV 2G"
case "AppleTV3,1":
return "Apple TV 3"
case "AppleTV3,2":
return "Apple TV 3 (2013)"
case "i386":
return "Simulator"
case "x86_64":
return "Simulator"
default:
return "Unknown Hardware \(model)"
}
return "Unknown Hardware \(model)"
}
@xumeng

This comment has been minimized.

Copy link

xumeng commented Sep 27, 2017

It needs to be updated. XD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.