Clicky

Apple Device Names

Look up Apple device names (iPhone10,6 → iPhone X)

$ curl http://appledevicenames.com/device/iPhone10,6

iPhone X

Use this to include the device name in support emails:

For info/diagnostic purposes:
  App v1.0.0 build 23 on iPhone X, iOS 11.0.3
//Stick this somewhere
private func deviceModel() -> String? {
    var keys = [CTL_HW, HW_MACHINE]
    var requiredSize = 0
    let fetchSizeResult = sysctl(&keys, UInt32(keys.count), nil, &requiredSize, nil, 0)
    guard fetchSizeResult == 0 else { return nil }
    var data = [CChar](repeating: 0, count: requiredSize)
    let fetchResult = sysctl(&keys, UInt32(keys.count), &data, &requiredSize, nil, 0)
    guard fetchResult == 0 else { return nil }
    return String(validatingUTF8: data)
}

//Stick this somewhere
func withDeviceName(block: @escaping (String) -> Void)  {
    let fallbackName = "Unknown"
    if let model = deviceModel(),
    let url = URL(string: "https://appledevicenames.com/device/\(model)") {
        URLSession.shared.dataTask(with: url) { data, _ , _ in
            DispatchQueue.main.async {
                if let data = data, let name = String(data: data, encoding: .utf8) {
                    block(name)
                } else {
                    block(fallbackName)
                }
            }
        }.resume()
    } else {
        block(fallbackName)
    }
}

//Calling code
withDeviceName { deviceName in
    let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString")
    let buildNumber = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion")
    let osVersion = UIDevice.current.systemVersion
    if let appVersion=appVersion, let buildNumber=buildNumber {
        let body = "For info/diagnostic purposes:\n  App v\(appVersion) build \(buildNumber) on \(deviceName), iOS \(osVersion)"
        //body = "For info/diagnostic purposes:\n  App v1.0.0 build 23 on iPhone X, iOS 11.0.3"
        //Use body
    }
}