0

How can I find out what device a user is using? The code I currently use is:

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if(screenBounds.size.height == 568){
    NSLog(@"User is using an iPhone 5s, 5c, or 5");
}
else{
    NSLog(@"User is using an iPhone 4s or earlier");
}

What other numbers could this return, and what device would it be? For example, I was hoping for something like this:

screenBounds.size.height == 568 would be an iPhone5/5s/5c
screenBounds.size.height == 480 would be an iPhone 4/5s
screenBounds.size.height > 570 would be an iPad

and so on. I'm going to be using this to change the nib file based on what device the user is using, so that I won't have to move every single button, image, label, or anything else with CGRectMake.

I'm not using auto layout because I would also like to have some more customization based on what device the user is using.

Jojodmo
  • 23,357
  • 13
  • 65
  • 107

1 Answers1

1

To check the kind of device:

if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
// You are using iPad
    return YES; 
}

else if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomiPhone )
{
  CGRect screenBounds = [[UIScreen mainScreen] bounds];

 if(screenBounds.size.height == 568){
    NSLog(@"User is using an iPhone 5+");

} else{
    NSLog(@"User is using an iPhone 4s-");
}
}
scollaco
  • 947
  • 8
  • 13
  • I still need to know iPad mini and things like that, though – Jojodmo Oct 26 '13 at 04:20
  • Well, I didn't do anything with iPad mini screen size yet, but I was looking for something about it and found the answer here: [link] (http://stackoverflow.com/questions/13366976/is-it-possible-to-detect-that-your-ios-app-is-running-on-an-ipad-mini-at-runtime). I hope this is what you are looking for. Good luck :) – scollaco Oct 26 '13 at 04:27
  • 4
    @Domenico The iPad mini is no different than the other iPads. It's the same screen resolution. It's just physically smaller. Use the same nib for any iPad or iPad mini. – rmaddy Oct 26 '13 at 04:31