4

Possible Duplicate:
How to find iPhone/iPod Device model(3G,3GS,4,4S) by code?
Detect device type

I want to identify iphone's model (3g,4s,5) programmatically.

then How can I find it?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • This link might help.. http://stackoverflow.com/questions/8426518/how-to-find-iphone-ipod-device-model3g-3gs-4-4s-by-code – rptwsthi Dec 26 '12 at 09:27

6 Answers6

12

you can easily detect iphone 3gs-4s, iphone5 and iPad with below condition:-

 if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
 {
     if ([[UIScreen mainScreen] bounds].size.height == 568)
     {

          //iphone 5
     }
     else
     {
         //iphone 3.5 inch screen iphone 3g,4s 
     }
 }
 else
 {
        //[ipad]
 }

just visit my answer at this Detect device type

Community
  • 1
  • 1
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
6

Please use the following code

#import <sys/utsname.h>

NSString* machineName()
{
    struct utsname systemInfo;
    uname(&systemInfo);

    return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
}

Identify your device type using following code

if([machineName() isEqualToString:@"iPhone1,2"])
{
    deviceType = @"iPhone 3G";
}
else if([machineName() isEqualToString:@"iPhone2,1"])
{
    deviceType = @"iPhone 3GS";
}
else if([machineName() isEqualToString:@"iPhone3,1"] || [machineName() isEqualToString:@"iPhone3,2"] || [machineName() isEqualToString:@"iPhone3,3"])
{
    deviceType = @"iPhone 4";
}
else if([machineName() isEqualToString:@"iPhone4,1"])
{
    deviceType = @"iPhone 4S";
}
else if([machineName() isEqualToString:@"iPhone5,1"])
{
    deviceType = @"iPhone 5";
}
else if([machineName() isEqualToString:@"iPod1,1"])
{
    deviceType = @"iPod Touch 1G";
}
else if([machineName() isEqualToString:@"iPod2,1"] || [machineName() isEqualToString:@"iPod2,2"])
{
    deviceType = @"iPod Touch 2G";
}
else if([machineName() isEqualToString:@"iPod3,1"])
{
    deviceType = @"iPod Touch 3G";
}
else if([machineName() isEqualToString:@"iPod4,1"])
{
    deviceType = @"iPod Touch 4G";
}
else if([machineName() isEqualToString:@"iPod5,1"])
{
    deviceType = @"iPod Touch 5G";
}
iDhaval
  • 7,824
  • 2
  • 21
  • 30
4

You can use the UIDevice (Hardware) category by Erica Sadun

It can be used as:

[[UIDevice currentDevice] platformType]   // ex: UIDevice4GiPhone

[[UIDevice currentDevice] platformString] // ex: @"iPhone 4G"
HDdeveloper
  • 4,396
  • 6
  • 40
  • 65
Akshay Shah
  • 1,120
  • 6
  • 13
2

You can use the following code for this:

NSString *device()
{
    struct utsname devInfo;
    uname(&devInfo);

    return [NSString stringWithCString:devInfo.machine encoding:NSUTF8StringEncoding];
}

Make sure that you import #import <sys/utsname.h>

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
1

HI please use below code

[UIDevice currentDevice] platformType]   // returns UIDevice4GiPhone
[[UIDevice currentDevice] platformString] // returns @"iPhone 4G"

or please check ratina

+ (BOOL) isRetina
{
    if([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
        return [[UIScreen mainScreen] scale] == 2.0 ? YES : NO;

    return NO;
}

or check ios version

   + (BOOL) isIOS5
    {
        NSString *os5 = @"5.0";
        NSString *currSysVer = [[UIDevice currentDevice] systemVersion];

        //    currSysVer = @"5.0.1";
        if ([currSysVer compare:os5 options:NSNumericSearch] == NSOrderedAscending) //lower than 4
        {
            return NO;
        }
        else if ([currSysVer compare:os5 options:NSNumericSearch] == NSOrderedDescending) //5.0.1 and above
        {        
            return YES;
        }
        else // IOS 5
        {
            return YES;
        }

        return NO;
    }
Praveen kalal
  • 2,148
  • 4
  • 19
  • 33
0

You can get these using uidevice-extension What you need are the following funcitons:

- (NSString *) platform;
- (NSString *) hwmodel;
- (NSUInteger) platformType;
- (NSString *) platformString;

from UIDevice-Hardware.h

Misha
  • 5,260
  • 6
  • 35
  • 63