i was using this function to know if there is a ipad
- (bool)bPAD {
return ([UIScreen mainScreen].bounds.size.height==1024);
}
but now i want to know if there is a iphone4 and i don't know how to do it
Thanks
A fast, easy to use, free, and community supported 2D game engine
i was using this function to know if there is a ipad
- (bool)bPAD {
return ([UIScreen mainScreen].bounds.size.height==1024);
}
but now i want to know if there is a iphone4 and i don't know how to do it
Thanks
I find it!!
- (bool)bIphone4 {
CGSize pixelBufferSize = [[[UIScreen mainScreen] currentMode] size];
return (pixelBufferSize.width == 640);
}Please don't use such hacks. You should use this:
BOOL bPAD = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
The idiom only tells you if it's an iPad or iPhone/iPodTouch. If you must know if it's a high-res screen you can check the scale of the mainScreen.
Note that the idiom only works on iPhone OS 3.2+ and the scale is only available on iOS 4.
This funcion
- (bool)bIphone4 {
CGSize pixelBufferSize = [[[UIScreen mainScreen] currentMode] size];
return (pixelBufferSize.width == 640);
}
run perfect in debugmode but when i mount a adhoc distribution do a nice EXCEPT. Any idea??
Wow! some hours later i find the solution:
- (bool)bIphone4 {
if([[UIScreen mainScreen] respondsToSelector:NSSelectorFromString(@"scale")])
{
return ([[UIScreen mainScreen] scale] > 1.9);
}
else return false;
}The challenge with using the mainScreen's scale to detect for iPhone4 is that an iPad running a normal iPhone 480x320 app in 2x scaled mode also returns 2.0.
The other challenge with using mainScreen's scale is that compiling versus a Base SDK of 3.2 or earlier causes a compilation error.
Here's a proposed solution that returns YES on iPhone4, NO on an iPad, and compiles cleanly with a Base SDK of 3.2:
// are we on a scaled screen (like iPhone4)?
static inline BOOL isHiResScaled(void)
{
// notes: this function was originally a test if the mainScreen's scale was >= 2.0f
// though this returned YES on an iPad running in 2x scaled mode
// and it caused a compilation error when trying to compile with a Base SDK of 3.2 or earlier
// we can detect the physical screen width on iOS 3.2+
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2f)
{
// yes if the physical screen width (in pixels) is 640
UIScreen* screen = [UIScreen mainScreen];
return (screen.currentMode.size.width == 640.0f);
}
// all iDevices before 3.2 were 480 x 320
return NO;
}You must log in to post.