Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(NSString *)getDevice{
- // vars
- NSString *this_device = @"";
- size_t size;
- sysctlbyname("hw.machine", NULL, &size, NULL, 0);
- char *machine = malloc(size + 1);
- sysctlbyname("hw.machine", machine, &size, NULL, 0);
- machine[size] = 0;
- NSString *machineString = [NSString stringWithFormat:@"%s", machine];
- //NSLog(@"%s", machine);
- // check
- if([machineString isEqualToString:@"iPad1,1"]){
- // set
- this_device = @"iPad1";
- }
- else if([machineString isEqualToString:@"iPad2,1"] || [machineString isEqualToString:@"iPad2,2"] || [machineString isEqualToString:@"iPad2,2"] || [machineString isEqualToString:@"iPad2,4"]){
- // set
- this_device = @"iPad2";
- }
- else if([machineString isEqualToString:@"iPad3,1"] || [machineString isEqualToString:@"iPad3,2"] || [machineString isEqualToString:@"iPad3,3"]){
- // set
- this_device = @"iPad3";
- }
- else if([machineString isEqualToString:@"iPad3,4"] || [machineString isEqualToString:@"iPad3,5"] || [machineString isEqualToString:@"iPad3,6"]){
- // set
- this_device = @"iPad4";
- }
- else if([machineString isEqualToString:@"iPad4,1"] || [machineString isEqualToString:@"iPad4,2"]){
- // set
- this_device = @"iPadAir";
- }
- else if([machineString isEqualToString:@"iPad2,5"] || [machineString isEqualToString:@"iPad2,6"] || [machineString isEqualToString:@"iPad2,7"]){
- // set
- this_device = @"iPadMini";
- }
- else if([machineString isEqualToString:@"iPad4,4"] || [machineString isEqualToString:@"iPad4,5"]){
- // set
- this_device = @"iPadMini2";
- }
- else if([machineString isEqualToString:@"iPhone1,1"]){
- // set
- this_device = @"iPhone2G";
- deviceWidth = 320;
- deviceHeight = 480;
- }
- else if([machineString isEqualToString:@"iPhone1,2"]){
- // set
- this_device = @"iPhone3G";
- deviceWidth = 320;
- deviceHeight = 480;
- }
- else if([machineString isEqualToString:@"iPhone2,1"]){
- // set
- this_device = @"iPhone3GS";
- deviceWidth = 320;
- deviceHeight = 480;
- }
- else if([machineString isEqualToString:@"iPhone3,1"] || [machineString isEqualToString:@"iPhone3,2"] || [machineString isEqualToString:@"iPhone3,3"]){
- // set
- this_device = @"iPhone4";
- deviceWidth = 320;
- deviceHeight = 480;
- }
- else if([machineString isEqualToString:@"iPhone4,1"]){
- // set
- this_device = @"iPhone4S";
- deviceWidth = 320;
- deviceHeight = 480;
- }
- else if([machineString isEqualToString:@"iPhone5,1"] || [machineString isEqualToString:@"iPhone5,2"]){
- // set
- this_device = @"iPhone5";
- deviceWidth = 320;
- deviceHeight = 568;
- }
- else if([machineString isEqualToString:@"iPhone5,3"] || [machineString isEqualToString:@"iPhone5,4"]){
- // set
- this_device = @"iPhone5C";
- deviceWidth = 320;
- deviceHeight = 568;
- }
- else if([machineString isEqualToString:@"iPhone6,1"] || [machineString isEqualToString:@"iPhone6,2"]){
- // set
- this_device = @"iPhone5S";
- deviceWidth = 320;
- deviceHeight = 568;
- }
- else if([machineString isEqualToString:@"iPhone7,2"]){
- // set
- this_device = @"iPhone6";
- deviceWidth = 375;
- deviceHeight = 667;
- }
- else if([machineString isEqualToString:@"iPhone7,1"]){
- // set
- this_device = @"iPhone6+";
- deviceWidth = 414;
- deviceHeight = 736;
- }
- else if([machineString isEqualToString:@"iPod1,1"]){
- // set
- this_device = @"iPod1";
- deviceWidth = 320;
- deviceHeight = 480;
- }
- else if([machineString isEqualToString:@"iPod2,1"]){
- // set
- this_device = @"iPod2";
- deviceWidth = 320;
- deviceHeight = 480;
- }
- else if([machineString isEqualToString:@"iPod3,1"]){
- // set
- this_device = @"iPod3";
- deviceWidth = 320;
- deviceHeight = 480;
- }
- else if([machineString isEqualToString:@"iPod4,1"]){
- // set
- this_device = @"iPod4"; // retina
- deviceWidth = 320;
- deviceHeight = 480;
- }
- else if([machineString isEqualToString:@"iPod5,1"]){
- // set
- this_device = @"iPod5"; // retina 568
- deviceWidth = 320;
- deviceHeight = 568;
- }
- else if([machineString isEqualToString:@"i386"]){
- // set
- this_device = @"Simulator";
- deviceWidth = 320;
- deviceHeight = 568;
- }
- else if([machineString isEqualToString:@"x86_64"]){
- // set
- this_device = @"iPhone Simulator";
- deviceWidth = 375;
- deviceHeight = 667;
- }
- else{
- // set
- this_device = @"Unknown";
- }
- // dealloc
- free(machine);
- NSLog(@"this device is %@", this_device);
- return this_device;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement