How can I check if an application running on iPhone 5 or not and then do something?
Asked
Active
Viewed 1.9k times
8
-
1Are 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 Answers
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
-
As in the other discussion it is really not necessary to check with epsilon – hfossli Apr 19 '13 at 14:05
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
-
5This 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
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
-
2
-
1yes, and many iPads run on iOS6, and they are also not iPhone5 devices in a case of universal application. – holex Apr 19 '13 at 09:45
-
3
-
-