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 l
just adding my 2 cents :
I see what you are doing here, but binding this to a specific value like 2.0 is good for the moment, but what if for example next iPad got resolution bump like x1.5 ? For me anything that goes above 1.0 is kind of higher-than-normal display so I will load hi-res graphics. Does not matter much then if that is iPad,iPhone ....
For detecting retina display on all devices including the new iPad
+(BOOL)isRetinaDisplay {
// since we call this alot, cache it
static CGFloat scale = 0.0;
if (scale == 0.0) {
// NOTE: In order to detect the Retina display reliably on all iOS devices,
// you need to check if the device is running iOS4+ and if the
// [UIScreen mainScreen].scale property is equal to 2.0.
// You CANNOT assume a device is running iOS4+ if the scale property exists,
// as the iPad 3.2 also contains this property.
// On an iPad running iOS3.2, scale will return 1.0 in 1x mode, and 2.0
// in 2x mode -- even though we know that device does not contain a Retina display.
// Apple changed this behavior in iOS4.2 for the iPad: it returns 1.0 in both
// 1x and 2x modes. You can test this yourself in the simulator.
// I test for the -displayLinkWithTarget:selector: method on the main screen
// which exists in iOS4.x but not iOS3.2, and then check the screen's scale:
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
([UIScreen mainScreen].scale == 2.0)) {
scale = 2.0;
return YES;
} else {
scale = 1.0;
return NO;
}
}
return scale > 1.0;
}
Credit to: Adriano Paladini http://developer.appcelerator.com/question/133826/detecting-new-ipad-3-dpi-and-retina
I know that the topic is a bit old now, but It might help some people. On Cocos2d you can load hi-resolution graphics for the iphone4 and low-resolution for iphone 3 using the -hd suffix on your files.
You just have to enable the retina display like this before:
// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
CCLOG(@"Retina Display Not supported");
For more information read the documentation here: RetinaDisplay in cocos2d
You could check the scale of the screen.
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2){
//iPhone 4
}
Despite what Apple's docs say, the UIScreen's scale property isn't just available in iOS4, it's also available in 3.2 on the iPad. This means it's probably an unreliable way to check which device you're on.
Instead, you should check if contentScaleFactor is available on your main window(or any UIView), and then check the scale value.
scale is available for iPad, however you can always use if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) to check whether it is iPad or iPhone/iTouch