2
votes

I have iphone app in which I was till now successfully checking is iphone 5 with following code (in my Prefix.pch file):

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

Now when I run on my iPhone 5, I get this height in log: 480 ([[UIScreen mainScreen] bounds].size.height)

I've updated my iPhone on iOS 7. Is there some other way to check if is iPhone 5 (or height of screen)?

UPDATE: I have on my MAC OSX 10.8.5

UPDATE 2: I've figured it out that there is some bug in that project because when I create new project all examples code work.

3
What does it matter if you're on an iPhone 5 vs an iPhone 4s? You should be checking for the capability you want to use, not what device you're on. - Dave DeLong
@DaveDeLong It matters if say iPhone 4 does not have enough juice to display all those nice rounded corner. Thus at run time, you check for the device and display the view accordingly. - Byte

3 Answers

3
votes

I just tested this code and it works checking for iPhone 5 & 4 and iOS 7 Just a bunch of pesky nested If statements!

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
            CGSize result = [[UIScreen mainScreen] bounds].size;
            CGFloat scale = [UIScreen mainScreen].scale;
            result = CGSizeMake(result.width * scale, result.height * scale);

            if(result.height == 960){
                NSLog(@"iphone 4, 4s retina resolution");

                //CODE IF IPHONE 4

                if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
                    //Code if iPhone 4 or 4s and iOS 7
                    NSLog(@"iPhone 4 iOS 7");
                }
            }
            if(result.height == 1136){
                NSLog(@"iphone 5 resolution");

                //CODE IF iPHONE 5

                if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
                    //Code if iPhone 5 or 5s and iOS 7
                    NSLog(@"iPhone 5 iOS 7");
                }
            }
        }
    }
2
votes

Use this :

bool isFourInches = CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136));

isFourInches will be "YES" if the device has a four inches display, it could be an iPhone 5, 5s or 5c...

0
votes

Try the condition below ...

 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){   

     NSLog(@"iOS 7");          
 }