Skip to content

Instantly share code, notes, and snippets.

@Winchariot
Created October 22, 2019 19:57
Show Gist options
  • Save Winchariot/4616b40df5c9b3610c790001631e0fe7 to your computer and use it in GitHub Desktop.
Save Winchariot/4616b40df5c9b3610c790001631e0fe7 to your computer and use it in GitHub Desktop.
Determine iPhone model... ish
//Phone model is not provided officially by any Cocoa API.
//It can be narrowed down to a few different models by checking the screen dimensions, but this shouldn't be relied upon
// and should NEVER drive any business logic.
//A good use for such knowledge is for something like error logging.
//https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
static var iPhoneModel: String? {
guard UIDevice().userInterfaceIdiom == .phone else { return nil }
switch UIScreen.main.nativeBounds.height {
case 1136:
return "5/5s/5c"
case 1334:
return "iPhone 6/6s/7/8"
case 1920, 2208:
return "iPhone 6+/6s+/7+/8+"
case 2436:
return "iPhone X/Xs/11 Pro"
case 2688:
return "iPhone Xs Max/11 Pro Max"
case 1792:
return "iPhone Xr/11"
default:
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment