Advertisement
khenid

Untitled

Mar 20th, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -(NSString *)getDevice{
  2.     // vars
  3.     NSString *this_device = @"";
  4.     size_t size;
  5.     sysctlbyname("hw.machine", NULL, &size, NULL, 0);
  6.     char *machine = malloc(size + 1);
  7.     sysctlbyname("hw.machine", machine, &size, NULL, 0);
  8.     machine[size] = 0;
  9.     NSString *machineString = [NSString stringWithFormat:@"%s", machine];
  10.     //NSLog(@"%s", machine);
  11.    
  12.     // check
  13.     if([machineString isEqualToString:@"iPad1,1"]){
  14.         // set
  15.         this_device = @"iPad1";
  16.     }
  17.     else if([machineString isEqualToString:@"iPad2,1"] || [machineString isEqualToString:@"iPad2,2"] || [machineString isEqualToString:@"iPad2,2"] || [machineString isEqualToString:@"iPad2,4"]){
  18.         // set
  19.         this_device = @"iPad2";
  20.     }
  21.     else if([machineString isEqualToString:@"iPad3,1"] || [machineString isEqualToString:@"iPad3,2"] || [machineString isEqualToString:@"iPad3,3"]){
  22.         // set
  23.         this_device = @"iPad3";
  24.     }
  25.     else if([machineString isEqualToString:@"iPad3,4"] || [machineString isEqualToString:@"iPad3,5"] || [machineString isEqualToString:@"iPad3,6"]){
  26.         // set
  27.         this_device = @"iPad4";
  28.     }
  29.     else if([machineString isEqualToString:@"iPad4,1"] || [machineString isEqualToString:@"iPad4,2"]){
  30.         // set
  31.         this_device = @"iPadAir";
  32.     }
  33.     else if([machineString isEqualToString:@"iPad2,5"] || [machineString isEqualToString:@"iPad2,6"] || [machineString isEqualToString:@"iPad2,7"]){
  34.         // set
  35.         this_device = @"iPadMini";
  36.     }
  37.     else if([machineString isEqualToString:@"iPad4,4"] || [machineString isEqualToString:@"iPad4,5"]){
  38.         // set
  39.         this_device = @"iPadMini2";
  40.     }
  41.     else if([machineString isEqualToString:@"iPhone1,1"]){
  42.         // set
  43.         this_device = @"iPhone2G";
  44.         deviceWidth = 320;
  45.         deviceHeight = 480;
  46.     }
  47.     else if([machineString isEqualToString:@"iPhone1,2"]){
  48.         // set
  49.         this_device = @"iPhone3G";
  50.         deviceWidth = 320;
  51.         deviceHeight = 480;
  52.     }
  53.     else if([machineString isEqualToString:@"iPhone2,1"]){
  54.         // set
  55.         this_device = @"iPhone3GS";
  56.         deviceWidth = 320;
  57.         deviceHeight = 480;
  58.     }
  59.     else if([machineString isEqualToString:@"iPhone3,1"] || [machineString isEqualToString:@"iPhone3,2"] || [machineString isEqualToString:@"iPhone3,3"]){
  60.         // set
  61.         this_device = @"iPhone4";
  62.         deviceWidth = 320;
  63.         deviceHeight = 480;
  64.     }
  65.     else if([machineString isEqualToString:@"iPhone4,1"]){
  66.         // set
  67.         this_device = @"iPhone4S";
  68.         deviceWidth = 320;
  69.         deviceHeight = 480;
  70.     }
  71.     else if([machineString isEqualToString:@"iPhone5,1"] || [machineString isEqualToString:@"iPhone5,2"]){
  72.         // set
  73.         this_device = @"iPhone5";
  74.         deviceWidth = 320;
  75.         deviceHeight = 568;
  76.     }
  77.     else if([machineString isEqualToString:@"iPhone5,3"] || [machineString isEqualToString:@"iPhone5,4"]){
  78.         // set
  79.         this_device = @"iPhone5C";
  80.         deviceWidth = 320;
  81.         deviceHeight = 568;
  82.     }
  83.     else if([machineString isEqualToString:@"iPhone6,1"] || [machineString isEqualToString:@"iPhone6,2"]){
  84.         // set
  85.         this_device = @"iPhone5S";
  86.         deviceWidth = 320;
  87.         deviceHeight = 568;
  88.     }
  89.     else if([machineString isEqualToString:@"iPhone7,2"]){
  90.         // set
  91.         this_device = @"iPhone6";
  92.         deviceWidth = 375;
  93.         deviceHeight = 667;
  94.     }
  95.     else if([machineString isEqualToString:@"iPhone7,1"]){
  96.         // set
  97.         this_device = @"iPhone6+";
  98.         deviceWidth = 414;
  99.         deviceHeight = 736;
  100.     }
  101.     else if([machineString isEqualToString:@"iPod1,1"]){
  102.         // set
  103.         this_device = @"iPod1";
  104.         deviceWidth = 320;
  105.         deviceHeight = 480;
  106.     }
  107.     else if([machineString isEqualToString:@"iPod2,1"]){
  108.         // set
  109.         this_device = @"iPod2";
  110.         deviceWidth = 320;
  111.         deviceHeight = 480;
  112.     }
  113.     else if([machineString isEqualToString:@"iPod3,1"]){
  114.         // set
  115.         this_device = @"iPod3";
  116.         deviceWidth = 320;
  117.         deviceHeight = 480;
  118.     }
  119.     else if([machineString isEqualToString:@"iPod4,1"]){
  120.         // set
  121.         this_device = @"iPod4"; // retina
  122.         deviceWidth = 320;
  123.         deviceHeight = 480;
  124.     }
  125.     else if([machineString isEqualToString:@"iPod5,1"]){
  126.         // set
  127.         this_device = @"iPod5"; // retina 568
  128.         deviceWidth = 320;
  129.         deviceHeight = 568;
  130.     }
  131.     else if([machineString isEqualToString:@"i386"]){
  132.         // set
  133.         this_device = @"Simulator";
  134.         deviceWidth = 320;
  135.         deviceHeight = 568;
  136.     }
  137.     else if([machineString isEqualToString:@"x86_64"]){
  138.         // set
  139.         this_device = @"iPhone Simulator";
  140.         deviceWidth = 375;
  141.         deviceHeight = 667;
  142.     }
  143.     else{
  144.         // set
  145.         this_device = @"Unknown";
  146.     }
  147.    
  148.     // dealloc
  149.     free(machine);
  150.    
  151.     NSLog(@"this device is %@", this_device);
  152.    
  153.     return this_device;
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement