0

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Wiem
  • 163
  • 8

5 Answers5

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
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
0

Use [[[UIDevice currentDevice] systemVersion] floatValue] to get version info.

wshcdr
  • 935
  • 2
  • 12
  • 27
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
0

May be you are looking for [[UIDevice currentDevice] model]

BaSha
  • 2,356
  • 3
  • 21
  • 38