How to differentiate between iphone4 and iphone 3

Ankur picture Ankur · Jul 20, 2010 · Viewed 18.6k times · Source

I am trying to build a game for the iphone using cocos2d engine. I wanted to know how can I tell a difference whether the user is using iphone 4 or iphone 3 as I wanted to load hi-resolution graphics for the iphone4 and low-resolution for iphone 3. I know if I use @2x.png at the end of the image file name UIImage loads the hi-resolution image by itself if I am using an iphone 4 but for the game I am using cocos2d engine's CCSprite class to load the graphics.

I would really appreciate the reply.

Regards, Ankur

Answer

Tom Irving picture Tom Irving · Jul 20, 2010

You could check the scale of the screen.

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2){
    //iPhone 4
}