-2

I am using cocos2d in iOS .

I am having a problem detecting the iphone5 resolution(1136*640).

I am using code:

CGRect screenBounds = [[UIScreen mainScreen] bounds];

When we run app on iPhone simulator (4 inch), it gives screenWidth and screnHeight-320,480 respectively.

Can anyone tell me the solution for this?

FuzzyBunnySlippers
  • 3,387
  • 2
  • 18
  • 28
  • 1
    possible duplicate of [How to get the screen width and height in iOS?](http://stackoverflow.com/questions/5677716/how-to-get-the-screen-width-and-height-in-ios) – Julian Jan 20 '14 at 12:07
  • You should not use those kind of tricks, your app should accomodate any different sizes. I'm pretty sure that cocos2d already does it for you. – Andrea Jan 20 '14 at 12:11
  • 2
    you are probably missing an 1136x640 default image for app startup in your resource bundle, and iOS is boxing the app to the iPhone 4 format. – YvesLeBorg Jan 20 '14 at 13:08
  • @Andrea : i am pretty certain cocos2d does not. It accommodates automagically the retina/standard resolutions, but for screen size you are on your own. Thus the question is valid. – YvesLeBorg Jan 20 '14 at 13:11
  • duplicate of "how to detect iPhone 5" http://stackoverflow.com/questions/12446990/how-to-detect-iphone-5-widescreen-devices – CodeSmile Jan 20 '14 at 17:27

3 Answers3

1

Write this code in .m file.

#define WIDESCREEN ( fabs( ( double )[ [UIScreen mainScreen ]bounds ].size.height-( double )568 ) < DBL_EPSILON )

Now you can know the screen size like this.

if(WIDESCREEN)
{
    NSLog(@"iPhone5 is here");
}
else
{
    NSLog(@"iPhone4 is here");
}
Surendra
  • 201
  • 3
  • 6
0

you can add checks in your code for iPhone 4inch screens and 3.5 inch screens

CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
    // iPhone Classic
    // set your frames for classic iPhone here
}
if(result.height == 568)
{
    // iPhone 5, iPhone 5S, iPhone 5C
    // set your frames for 4 inch iPhone here
}
-1

iPhone 5 resolution is 1136*640 only. If you wanna check just Log below Code

the resolution it will give exactly (1136*640)

CGRect screenBounds = [[UIScreen mainScreen] bounds];
                        CGFloat screenScale = [[UIScreen mainScreen] scale];
                        CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);


   NSLog(@"Screen SIze %@",NSStringFromCGSize (screenSize));




#define IS_IPHONE5          ([[UIScreen mainScreen] bounds].size.width >= 568 || [[UIScreen mainScreen] bounds].size.height >= 568)?YES:NO

    #define IS_IPHONE4          ([[UIScreen mainScreen] bounds].size.width >= 480 || [[UIScreen mainScreen] bounds].size.height >= 480)?YES:NO


if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {

         if(IS_IPHONE4)
             {
                         // iPhone 4        
              }
         if(IS_IPHONE5)
               {
                        // iPhone 5

               }
     }       
Yohan
  • 1,108
  • 9
  • 21