2

I'm wondering is that possible to get the iOS device model number programmatically. I mean the device model on the back of iPhone. It's always in this format "AXXXX".

bourvill
  • 152
  • 1
  • 13
RayChen
  • 1,417
  • 2
  • 17
  • 36

2 Answers2

2

With a little use of private API it is possible

let device = UIDevice.current
var selector = NSSelectorFromString("deviceInfoForKey:")
if !device.responds(to: selector) {
    selector = NSSelectorFromString("_deviceInfoForKey:")
}
if device.responds(to: selector) {
    if let unmanagedModel = device.perform(selector, with:"ModelNumber") {
        let model = unmanagedModel.takeRetainedValue() as! String
        print("Device hardware model: \(model)")
    }
}
Andrey Kuznetsov
  • 843
  • 1
  • 18
  • 29
-5
let myDevice = UIDevice.currentDevice()
let deviceModel = myDevice.model
Humxaa Khan
  • 59
  • 1
  • 8