I made a game and I have a method that I want to run differently depending whether it is an iphone 4, or 5. Does anybody know of a way to do this.
Asked
Active
Viewed 92 times
5 Answers
2
You can use below code:
#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)
#define IS_RETINA ([[UIScreen mainScreen] scale] == 2.0f)

Son Nguyen
- 3,481
- 4
- 33
- 47
-
-
Follow this question: http://stackoverflow.com/questions/448162/determine-device-iphone-ipod-touch-with-iphone-sdk/1561920#1561920 – Son Nguyen Jul 10 '14 at 09:48
1
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
for iphone 5,5c and 5s
}
else
{
for other device 4 4s
}

Manjit Singh
- 238
- 2
- 10
-
-
you can check the height of any device using this code replace the 568 with the height of your device – Manjit Singh Jul 10 '14 at 11:58
0
I usually add these macro definitions in the "App Name-Prefix.pch" file (so they are accessible everywhere with no need to import that file):
#define IS_iPHONE_5 [[UIScreen mainScreen] bounds].size.height == 568
#define IS_iPHONE [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone
#define IS_iPAD [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad
#define iDEVICE_TYPE (IS_iPAD) ? @"iPad" : ((IS_iPHONE_5) ? @"iPhone5" : @"iPhone")
If I am using using .xib files, I create 3 different .xib-s for every view controller, and I put ~iPhone, ~iPhone5, and ~iPad at the end of their name. And when I need to load the corresponding nib, I just write:
NSString *nameOfNib = [NSString stringWithFormat:@"ADWRootViewController~%@", iDEVICE_TYPE];
ADWRootViewController *rootVC = [[ADWRootViewController alloc] initWithNibName:nameOfNib
bundle:nil];
I hope it helped. NOTE that I do not check if it Retina or Non-Retina device in my code.

ppalancica
- 4,236
- 4
- 27
- 42