Monday, October 12, 2015

Get the device type and iOS version

Update: December 10, 2016 / September 23, 2017
Xcode 8.1 (Swift 3.0.1) / Xcode 9.0 (Swift 4)

Swift 3/Swift 4 Code:

let systemVersion = UIDevice.current.systemVersion
print("iOS\(systemVersion)")
        
//iPhone or iPad
let model = UIDevice.current.model

print("device type=\(model)")

Result:

iOS10.1.1
device type=iPhone

Original post: October 12, 2015

Swift 1 Code:

let systemVersion = UIDevice.currentDevice().systemVersion
println("iOS\(systemVersion)")
        
//iPhone or iPad
let model = UIDevice.currentDevice().model
println("device type=\(model)")


Result:

iOS8.4.1
device type=iPad


To get the device model name string:

For Swift 2.0:

For Swift 1.2:

1 comment: