Translate

Tuesday, May 29, 2012

How to get device name?

device name

.h file

#include <sys/utsname.h>

+(NSString*)deviceName;

.m file

+(NSString*)deviceName
{
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString* platform =  [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
   
    NSString *deviceName;
   
    if ([platform isEqualToString:@"iPad1,1"])  
    {
        deviceName = @"iPad(WiFi)";
    }
    else if ([platform isEqual:@"iPad1,2"])
    {
        deviceName = @"iPad3G";
    }
    else if ([platform isEqualToString:@"iPad2,1"])
    {
        deviceName = @"iPad2(WiFi)";
    }
    else if ([platform isEqualToString:@"iPad2,2"])
    {
        deviceName = @"iPad2(GSM)";
    }
    else if ([platform isEqualToString:@"iPad2,3"])
    {
        deviceName = @"iPad2(CDMA)";
    }
    else if ([platform isEqualToString:@"iPad2,4"])
    {
        deviceName = @"iPad2";
    }
    else if ([platform isEqualToString:@"iPad3,1"])
    {
        deviceName = @"iPad3G(WiFi)";
    }
    else if ([platform isEqualToString:@"iPad3,2"])
    {
        deviceName = @"iPad3G(4G)";
    }
    else if ([platform isEqualToString:@"iPad3,3"])
    {
        deviceName = @"iPad3G(4G)";
    }
    else if ([platform isEqualToString:@"iPhone1,1"])
    {
        deviceName = @"iPhone1G";
    }
    else if ([platform isEqualToString:@"iPhone1,2"])
    {
        deviceName = @"iPhone3G";
    }
    else if ([platform isEqualToString:@"iPhone2,1"])
    {
        deviceName = @"iPhone3GS";
    }
    else if ([platform isEqualToString:@"iPhone3,1"] || [platform isEqual:@"iPhone3,2"] || [platform isEqual:@"iPhone3,3"])
    {
        deviceName = @"iPhone4";
    }
    else if ([platform isEqualToString:@"iPhone3,3"])
    {
        deviceName = @"VerizoniPhone 4";
    }
    else if ([platform isEqualToString:@"iPhone4,1"])
    {
        deviceName = @"iPhone4S";
    }
    else if ([platform isEqualToString:@"iPod1,1"])
    {
        deviceName = @"iPod1stGen";
    }
    else if ([platform isEqualToString:@"iPod2,1"])
    {
        deviceName = @"iPod2ndGen";
    }
    else if ([platform isEqualToString:@"iPod3,1"])
    {
        deviceName = @"iPod3rdGen";
    }
    else if ([platform isEqualToString:@"iPod4,1"])
    {
        deviceName = @"iPod4thGen";
    }
    else if ([platform isEqualToString:@"x86_64"] || [platform isEqualToString:@"i386"])
    {
        deviceName = @"Simulator";
    }
    return deviceName;
}


or  if viewcontroller

- (void)viewDidLoad
{
    [super viewDidLoad];
     
    [ViewController deviceName];
}








No comments:

Post a Comment