1

Possible Duplicate:
How to differentiate between iphone4 and iphone 3

Well, I know all the @2x stuff and already read the other stackoverflow threads and apple reference regarding the retina display and high res support to no avail.

I'm loading an image from a remote server which supports a resolution request parameter. For iPhone4 I want to request a larger resolution image.

How do I test if I'm on iPhone 4 ?

Using the "model" field on UIDevice is not an option because I'm not getting the right value in simulator.

Community
  • 1
  • 1
Yoni Shalom
  • 489
  • 4
  • 11

1 Answers1

4

I use this code for similar purposes.

// Return YES if we're running on a device with a retina display.
BOOL hasRetinaDisplay(void)
{
        if([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
                return [[UIScreen mainScreen] scale] == 2.0 ? YES : NO;

        return NO;
}

This works in that UIScreen only responds to scale on versions of iOS that can run on devices with retina displays, so if UIScreen doesn't respond to scale, then we know by default, no retina screen. If it does, then check its scale factor, 1.0 is no retina display, 2.0 is iPhone4.

jer
  • 20,094
  • 5
  • 45
  • 69
  • Of course, UIScreen, how didn't I think of that. Thanks. – Yoni Shalom Jul 26 '10 at 14:00
  • If you need the check in different locations within your code, you can put the above code in a category of UIScreen, then just call: [[UIScreen mainscreen] isRetina] for example. –  Jun 07 '11 at 11:18