-2

I am new to iOS development. How can I know about the device which my application is currently installed. I want the code for checking whether the current device is iPad or iPhone on the iOS simulator.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user3418619
  • 235
  • 1
  • 2
  • 14
  • possible duplicate of [How to detect iPhone 5 (widescreen devices)?](http://stackoverflow.com/questions/12446990/how-to-detect-iphone-5-widescreen-devices) – Bryan Chen Apr 08 '14 at 06:03

4 Answers4

0

The best way to find whether the device is iPad or iPhone is

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
     // The device is an iPad running iPhone 3.2 or later.
}
else
{
     // The device is an iPhone or iPod touch.
}

If you want more details on what kind of device, see https://gist.github.com/Jaybles/1323251

Satheesh
  • 10,998
  • 6
  • 50
  • 93
0
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
     // The device is an iPad
}
else
{
     // The device is an iPhone

     if(([[UIScreen mainScreen] bounds].size.height>520))
     {
        // The device is an iPhone5
     }
     else
     {
        // The device is an iPhone4
     }
}
Tapas Pal
  • 7,073
  • 8
  • 39
  • 86
  • Beyond detecting whether you are running on iPad or iPhone/iPod Touch, I wouldn't treat iPhone 5 as a special case, but write the code to run with any screen size. – gnasher729 Apr 08 '14 at 06:51
  • user3418619 is commenting on satheeshwaran answer that `i want to know that divice is iphone4 ipnoe5 or Ipad..` – Tapas Pal Apr 08 '14 at 07:18
0

Add this code it may help:

#define isiPhone5  ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE
#define isiPhone  (UI_USER_INTERFACE_IDIOM() == 0)?TRUE:FALSE

And than use as

 if(isiPhone)
            {      

                if (isiPhone5)
                { 

                    //Code for iphone 5

                }
                else
                {
                    //iphone 3.5 inch screen

                }       
            }
            else
            {
                //[ipad]

            }

Happy coding

Rahul Patel
  • 5,858
  • 6
  • 46
  • 72
0

Use this

+ (NSString *)yesButWhichDeviceIsIt
{
BOOL hasRetina = NO;
if ([UIScreen instancesRespondToSelector:@selector(scale)]) {
    CGFloat scale = [[UIScreen mainScreen] scale];
    if (scale > 1.0) {
        hasRetina = YES;
    }
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    if (hasRetina) {
        return @"iPad retina";
    } else {
        return @"iPad";
    }
 }
 else {
    if (hasRetina) {
        if ([[UIScreen mainScreen] bounds].size.height == 568){
            return @"iPhone5";
        }
        else
        {
            return @"iPhone4s";
        }
    } else {
        return @"iPhone";
    }
}
}

Here return type is String which will give you device type

Charan Giri
  • 1,097
  • 1
  • 9
  • 15