8

How can I check if an application running on iPhone 5 or not and then do something?

Hemang
  • 26,840
  • 19
  • 119
  • 186
iWizard
  • 6,816
  • 19
  • 67
  • 103
  • 1
    Are you really checking for an iPhone 5 or do you need to check for the 4" screen currently used by both the iPhone 5 and 5th gen iPod touch? And what do you plan to do with this knowledge? The answers will help guide the best solution. – rmaddy Nov 05 '12 at 22:09
  • @ChrisLatta - I searched and I did not find so sorry but this is not duplicated then. – iWizard Nov 06 '12 at 09:35
  • 1
    @CroiOS why is it not a duplicate? – hfossli Apr 19 '13 at 14:03

6 Answers6

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

then in the code:

if (IS_IPHONE_5) { 
   //is iphone 5
}
Piero
  • 9,173
  • 18
  • 90
  • 160
12

You're likely concerned with the window size, not the make/model, this will do:

CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
if (screenRect.size.height == 568)
{
 // this is an iPhone 5+
}
CSmith
  • 13,318
  • 3
  • 39
  • 42
  • missing info here. @property(nonatomic,readonly) CGRect bounds; // Bounds of entire screen in points @property(nonatomic,readonly) CGRect applicationFrame; // Frame of application screen area in points (i.e. entire screen minus status bar if visible) – Underdog Feb 06 '13 at 09:59
  • 5
    This is not always true, if in your application status bar is visible its height is 548. To have this always equal to 568 use [[UIScreen mainScreen] bounds]; instead. – Underdog Feb 07 '13 at 06:03
3

You can do it with checking screen resolution or you can do it with using:

#import "sys/utsname.h"

which give you identifier for each device. Just see my answer here: recognize device

Community
  • 1
  • 1
edzio27
  • 4,126
  • 7
  • 33
  • 48
3

Using screen is fine.

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0f)

No epsilon check is required

hfossli
  • 22,616
  • 10
  • 116
  • 130
0

We can directly put this method in constant file and can use any where using define

#define ISIPHONE5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
#define HEIGHT (ISIPHONE5 ? 60:145)

Or can use

 #define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)

We can also check IOS via below

#define IOS_OLDER_THAN_6 ([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0 )
#define IOS_NEWER_OR_EQUAL_TO_6 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0 )
sinh99
  • 3,909
  • 32
  • 32
-11

You can check your device's iOS version if is 6.0 then its a iPhone 5.....

Here's the code..

double osVersion = [[[UIDevice currentDevice] systemVersion] doubleValue];
NSLog(@"OSVersion: %f", osVersion);
if (osVersion == 6.0) 
{
  //Paste your code here.....
}
Deep Batra
  • 112
  • 5