Get iPhone Device Version

Here’s a quick way to separate iPhone 4 / iPhone 3 code paths — back when “retina display” was the shiny new thing:

float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 3.0) {
    // add your code for iphone 4 (retina display!)
} else {
    // add your code for iphone 3/3Gs
}

Why this was the wrong check (even then)

The snippet above conflates two different questions, and I knew better eventually:

  • OS version is not device capability. systemVersion tells you which iOS you’re running, not which hardware you’re on. iPhone 3GS units ran iOS 4 fine, and iPhone 4 always shipped with iOS 4+ — so this branch caught neither dimension correctly.
  • floatValue silently truncates. “10.3.4” parses as 10.3, and version comparison by float breaks down entirely at major-version boundaries. Compare NSString values or use NSProcessInfo.operatingSystemVersion (iOS 8+) if you truly need an OS check.
  • The right 2010-era check for retina was [[UIScreen mainScreen] scale] > 1.0 — ask about the screen, not the OS. For iPad, iOS 3.2 introduced [UIDevice userInterfaceIdiom].

Where this stands now

All of this is ancient history: UIDevice.systemVersion still exists (as a String), but the modern rule is capability- and trait-based — size classes, displayScale, and #available/@available checks instead of hand-rolled version parsing. Keep this snippet only as a reminder of how we used to do it.

Leave a Reply

Your email address will not be published. Required fields are marked *