标签:
本文地址; 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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/zhaoyabei/article/details/46697859