概述
3种方法获取设备硬件类型(最新到iPhone6)
1.这种是在较高层次获取设备类型,返回的是 iPhone , iPod , iPad 。适合要求不高的。
NSString *deviceType = [[UIDevice currentDevice] model];
2.这是Linux中获取设备类型的方法,主要是C语言的方法,注意引入头文件 #include <sys sysctl.h=""> 。输入底层获取设备类型的方法。
- (NSString *)getDeviceVersionInfo
{
size_t size;
// get the length of machine name
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
// get machine name
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithFormat:@"%s", machine];
free(machine);
return platform;
}
-(NSString *)correspondVersion
{
NSString *correspondVersion = [self getDeviceVersionInfo];
if ([correspondVersion isEqualToString:@"iPhone1,1"]) return @"iPhone 2G (A1203)";
if ([correspondVersion isEqualToString:@"iPhone1,2"]) return @"iPhone 3G (A1241/A1324)";
if ([correspondVersion isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS (A1303/A1325)";
if ([correspondVersion isEqualToString:@"iPhone3,1"]) return @"iPhone 4 (A1332)";
if ([correspondVersion isEqualToString:@"iPhone3,2"]) return @"iPhone 4 (A1332)";
if ([correspondVersion isEqualToString:@"iPhone3,3"]) return @"iPhone 4 (A1349)";
if ([correspondVersion isEqualToString:@"iPhone4,1"]) return @"iPhone 4S (A1387/A1431)";
if ([correspondVersion isEqualToString:@"iPhone5,1"]) return @"iPhone 5 (A1428)";
if ([correspondVersion isEqualToString:@"iPhone5,2"]) return @"iPhone 5 (A1429/A1442)";
if ([correspondVersion isEqualToString:@"iPhone5,3"]) return @"iPhone 5c (A1456/A1532)";
if ([correspondVersion isEqualToString:@"iPhone5,4"]) return @"iPhone 5c (A1507/A1516/A1526/A1529)";
if ([correspondVersion isEqualToString:@"iPhone6,1"]) return @"iPhone 5s (A1453/A1533)";
if ([correspondVersion isEqualToString:@"iPhone6,2"]) return @"iPhone 5s (A1457/A1518/A1528/A1530)";
if ([correspondVersion isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus (A1522/A1524)";
if ([correspondVersion isEqualToString:@"iPhone7,2"]) return @"iPhone 6 (A1549/A1586)";
if ([correspondVersion isEqualToString:@"iPod1,1"])
return @"iPod Touch 1G (A1213)";
if ([correspondVersion isEqualToString:@"iPod2,1"])
return @"iPod Touch 2G (A1288)";
if ([correspondVersion isEqualToString:@"iPod3,1"])
return @"iPod Touch 3G (A1318)";
if ([correspondVersion isEqualToString:@"iPod4,1"])
return @"iPod Touch 4G (A1367)";
if ([correspondVersion isEqualToString:@"iPod5,1"])
return @"iPod Touch 5G (A1421/A1509)";
if ([correspondVersion isEqualToString:@"iPad1,1"])
return @"iPad 1G (A1219/A1337)";
if ([correspondVersion isEqualToString:@"iPad2,1"])
return @"iPad 2 (A1395)";
if ([correspondVersion isEqualToString:@"iPad2,2"])
return @"iPad 2 (A1396)";
if ([correspondVersion isEqualToString:@"iPad2,3"])
return @"iPad 2 (A1397)";
if ([correspondVersion isEqualToString:@"iPad2,4"])
return @"iPad 2 (A1395+New Chip)";
if ([correspondVersion isEqualToString:@"iPad2,5"])
return @"iPad Mini 1G (A1432)";
if ([correspondVersion isEqualToString:@"iPad2,6"])
return @"iPad Mini 1G (A1454)";
if ([correspondVersion isEqualToString:@"iPad2,7"])
return @"iPad Mini 1G (A1455)";
if ([correspondVersion isEqualToString:@"iPad3,1"])
return @"iPad 3 (A1416)";
if ([correspondVersion isEqualToString:@"iPad3,2"])
return @"iPad 3 (A1403)";
if ([correspondVersion isEqualToString:@"iPad3,3"])
return @"iPad 3 (A1430)";
if ([correspondVersion isEqualToString:@"iPad3,4"])
return @"iPad 4 (A1458)";
if ([correspondVersion isEqualToString:@"iPad3,5"])
return @"iPad 4 (A1459)";
if ([correspondVersion isEqualToString:@"iPad3,6"])
return @"iPad 4 (A1460)";
if ([correspondVersion isEqualToString:@"iPad4,1"])
return @"iPad Air (A1474)";
if ([correspondVersion isEqualToString:@"iPad4,2"])
return @"iPad Air (A1475)";
if ([correspondVersion isEqualToString:@"iPad4,3"])
return @"iPad Air (A1476)";
if ([correspondVersion isEqualToString:@"iPad4,4"])
return @"iPad Mini 2G (A1489)";
if ([correspondVersion isEqualToString:@"iPad4,5"])
return @"iPad Mini 2G (A1490)";
if ([correspondVersion isEqualToString:@"iPad4,6"])
return @"iPad Mini 2G (A1491)";
if ([correspondVersion isEqualToString:@"i386"])
return @"iPhone Simulator";
if ([correspondVersion isEqualToString:@"x86_64"])
return @"iPhone Simulator";
return correspondVersion;
}
3.这是2一样,是Linux中获取设备类型的方法,主要是C语言的方法,注意引入头文件 #import "sys/utsname.h" 。输入底层获取设备类型的方法。
#import "sys/utsname.h"
- (NSString *)getDeviceVersionInfo
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *platform = [NSString stringWithFormat:@"%s", systemInfo.machine];
return platform;
}
-(NSString *)correspondVersion
{
NSString *correspondVersion = [self getDeviceVersionInfo];
if ([correspondVersion isEqualToString:@"iPhone1,1"]) return @"iPhone 2G (A1203)";
if ([correspondVersion isEqualToString:@"iPhone1,2"]) return @"iPhone 3G (A1241/A1324)";
if ([correspondVersion isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS (A1303/A1325)";
if ([correspondVersion isEqualToString:@"iPhone3,1"]) return @"iPhone 4 (A1332)";
if ([correspondVersion isEqualToString:@"iPhone3,2"]) return @"iPhone 4 (A1332)";
if ([correspondVersion isEqualToString:@"iPhone3,3"]) return @"iPhone 4 (A1349)";
if ([correspondVersion isEqualToString:@"iPhone4,1"]) return @"iPhone 4S (A1387/A1431)";
if ([correspondVersion isEqualToString:@"iPhone5,1"]) return @"iPhone 5 (A1428)";
if ([correspondVersion isEqualToString:@"iPhone5,2"]) return @"iPhone 5 (A1429/A1442)";
if ([correspondVersion isEqualToString:@"iPhone5,3"]) return @"iPhone 5c (A1456/A1532)";
if ([correspondVersion isEqualToString:@"iPhone5,4"]) return @"iPhone 5c (A1507/A1516/A1526/A1529)";
if ([correspondVersion isEqualToString:@"iPhone6,1"]) return @"iPhone 5s (A1453/A1533)";
if ([correspondVersion isEqualToString:@"iPhone6,2"]) return @"iPhone 5s (A1457/A1518/A1528/A1530)";
if ([correspondVersion isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus (A1522/A1524)";
if ([correspondVersion isEqualToString:@"iPhone7,2"]) return @"iPhone 6 (A1549/A1586)";
if ([correspondVersion isEqualToString:@"iPod1,1"])
return @"iPod Touch 1G (A1213)";
if ([correspondVersion isEqualToString:@"iPod2,1"])
return @"iPod Touch 2G (A1288)";
if ([correspondVersion isEqualToString:@"iPod3,1"])
return @"iPod Touch 3G (A1318)";
if ([correspondVersion isEqualToString:@"iPod4,1"])
return @"iPod Touch 4G (A1367)";
if ([correspondVersion isEqualToString:@"iPod5,1"])
return @"iPod Touch 5G (A1421/A1509)";
if ([correspondVersion isEqualToString:@"iPad1,1"])
return @"iPad 1G (A1219/A1337)";
if ([correspondVersion isEqualToString:@"iPad2,1"])
return @"iPad 2 (A1395)";
if ([correspondVersion isEqualToString:@"iPad2,2"])
return @"iPad 2 (A1396)";
if ([correspondVersion isEqualToString:@"iPad2,3"])
return @"iPad 2 (A1397)";
if ([correspondVersion isEqualToString:@"iPad2,4"])
return @"iPad 2 (A1395+New Chip)";
if ([correspondVersion isEqualToString:@"iPad2,5"])
return @"iPad Mini 1G (A1432)";
if ([correspondVersion isEqualToString:@"iPad2,6"])
return @"iPad Mini 1G (A1454)";
if ([correspondVersion isEqualToString:@"iPad2,7"])
return @"iPad Mini 1G (A1455)";
if ([correspondVersion isEqualToString:@"iPad3,1"])
return @"iPad 3 (A1416)";
if ([correspondVersion isEqualToString:@"iPad3,2"])
return @"iPad 3 (A1403)";
if ([correspondVersion isEqualToString:@"iPad3,3"])
return @"iPad 3 (A1430)";
if ([correspondVersion isEqualToString:@"iPad3,4"])
return @"iPad 4 (A1458)";
if ([correspondVersion isEqualToString:@"iPad3,5"])
return @"iPad 4 (A1459)";
if ([correspondVersion isEqualToString:@"iPad3,6"])
return @"iPad 4 (A1460)";
if ([correspondVersion isEqualToString:@"iPad4,1"])
return @"iPad Air (A1474)";
if ([correspondVersion isEqualToString:@"iPad4,2"])
return @"iPad Air (A1475)";
if ([correspondVersion isEqualToString:@"iPad4,3"])
return @"iPad Air (A1476)";
if ([correspondVersion isEqualToString:@"iPad4,4"])
return @"iPad Mini 2G (A1489)";
if ([correspondVersion isEqualToString:@"iPad4,5"])
return @"iPad Mini 2G (A1490)";
if ([correspondVersion isEqualToString:@"iPad4,6"])
return @"iPad Mini 2G (A1491)";
if ([correspondVersion isEqualToString:@"i386"])
return @"iPhone Simulator";
if ([correspondVersion isEqualToString:@"x86_64"])
return @"iPhone Simulator";
return correspondVersion;
}
最后
以上就是隐形水蜜桃为你收集整理的iOS开发获取手机型号 (设备硬件类型)的全部内容,希望文章能够帮你解决iOS开发获取手机型号 (设备硬件类型)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复