Skip to content

Instantly share code, notes, and snippets.

@saoudrizwan
Last active August 14, 2017 10:15
Show Gist options
  • Select an option

  • Save saoudrizwan/05cb8540affd8d24f01bef0b57ffe544 to your computer and use it in GitHub Desktop.

Select an option

Save saoudrizwan/05cb8540affd8d24f01bef0b57ffe544 to your computer and use it in GitHub Desktop.
import UIKit
extension UIDevice {
enum DevicePlatform: String {
case other = "Old Device"
case iPhone6S = "iPhone 6S"
case iPhone6SPlus = "iPhone 6S Plus"
case iPhone7 = "iPhone 7"
case iPhone7Plus = "iPhone 7 Plus"
}
var platform: DevicePlatform {
get {
var sysinfo = utsname()
uname(&sysinfo)
let platform = String(bytes: Data(bytes: &sysinfo.machine, count: Int(_SYS_NAMELEN)), encoding: .ascii)!.trimmingCharacters(in: .controlCharacters)
switch platform {
case "iPhone9,2", "iPhone9,4":
return .iPhone7Plus
case "iPhone9,1", "iPhone9,3":
return .iPhone7
case "iPhone8,2":
return .iPhone6SPlus
case "iPhone8,1":
return .iPhone6S
default:
return .other
}
}
}
var hasTapticEngine: Bool {
get {
return platform == .iPhone6S || platform == .iPhone6SPlus ||
platform == .iPhone7 || platform == .iPhone7Plus
}
}
var hasHapticFeedback: Bool {
get {
return platform == .iPhone7 || platform == .iPhone7Plus
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment