本文地址; http://blog.csdn.net/zhaoyabei/article/details/46697859
應用統計中有時候需要上傳設備型號,如果這樣寫:
[[UIDevice currentDevice] model]
獲得的設備型號不是具體型號,如在iPhone5S上面運行,實測得到字符串為@”iPhone”,我想要的是具體型號。
這裡提供一個方法來獲得設備具體型號(版本與機型的對應關系來源於維基百科):
- (NSString *)platform{
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
//未考慮iPhone3等較老設備,未考慮iPad設備(公司的應用不支持iPad)
if ([deviceString hasPrefix:@iPhone3]) return @iPhone 4;
if ([deviceString isEqualToString:@iPhone4,1]) return @iPhone 4S;
if ([deviceString isEqualToString:@iPhone5,1]||[deviceString isEqualToString:@iPhone5,2]) return @iPhone 5;
if ([deviceString isEqualToString:@iPhone5,3]||[deviceString isEqualToString:@iPhone5,4]) return @iPhone 5C;
if ([deviceString hasPrefix:@iPhone6]) return @iPhone 5S;
if ([deviceString isEqualToString:@iPhone7,1]) return @iPhone 6 Plus;
if ([deviceString isEqualToString:@iPhone7,2]) return @iPhone 6;
if ([deviceString isEqualToString:@i386]) return @Simulator;
if ([deviceString isEqualToString:@x86_64]) return @Simulator;
//如果沒有匹配直接返回系統提供的類似@iPhone5,3這種型號
return deviceString;
}