[[UIDevice currentDevice]model];方法也只能获取到当前手机是苹果哪个系列的产品,比如说使用这个方法是区分不了同系列的产品的,例如区分iphone5、iphone5c、和iphone5s,以及6和6P等。下面给大家一种方法,精确获取当前手机的型号:
该方法的返回值是个NSString,也就是当前使用的手机的名称,一下我只列出了部分机型,如果没有您想要的机型或者说将来苹果会出新的机型的话,你只需要在我标注的地方添加任意你想要的机型!
非常的方便,希望帮助大家!
- (NSString*)myMobileName
{
struct utsname systemInfo;
uname(&systemInfo);
NSString* code = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
static NSDictionary* deviceNamesByCode = nil;
if (!deviceNamesByCode) {
deviceNamesByCode = @{@"i386" :@"Simulator",
@"iPod1,1" :@"iPod Touch", // (Original)
@"iPod2,1" :@"iPod Touch", // (Second Generation)
@"iPod3,1" :@"iPod Touch", // (Third Generation)
@"iPod4,1" :@"iPod Touch", // (Fourth Generation)
@"iPhone1,1" :@"iPhone", // (Original)
@"iPhone1,2" :@"iPhone", // (3G)
@"iPhone2,1" :@"iPhone", // (3GS)1400
@"iPhone3,1" :@"iPhone 4", // (GSM)1420
@"iPhone3,3" :@"iPhone 4", // (CDMA/Verizon/Sprint)1420
@"iPhone4,1" :@"iPhone 4S", //1430
@"iPhone5,1" :@"iPhone 5", // (model A1428, AT&T/Canada)
@"iPhone5,2" :@"iPhone 5", // (model A1429, everything else)
@"iPhone5,3" :@"iPhone 5c", // (model A1456, A1532 | GSM)
@"iPhone5,4" :@"iPhone 5c", // (model A1507, A1516, A1526 (China), A1529 | Global)
@"iPhone6,1" :@"iPhone 5s", // (model A1433, A1533 | GSM)
@"iPhone6,2" :@"iPhone 5s", // (model A1457, A1518, A1528 (China), A1530 | Global)
@"iPhone7,1" :@"iPhone 6 Plus", // 1810
@"iPhone7,2" :@"iPhone 6", // 2915
------------------------********可以继续添加你想要的机型**********--------------------
};
}
NSString* mobileName = [deviceNamesByCode objectForKey:code];
return mobileName;
}