iOS 判断手机型号/系统版本

iOS开发中有时需要获取具体的手机型号和系统版本,代码入下:

1、首先导入头文件:<sys/utsname.h>

#import <sys/utsname.h>

2、复制下面的代码:

struct utsname systemInfo;
uname(&systemInfo);
NSString*phoneType = [NSString stringWithCString: systemInfo.machine encoding:NSASCIIStringEncoding];

if([phoneType  isEqualToString:@"iPhone1,1"])  return@"iPhone 2G";

if([phoneType  isEqualToString:@"iPhone1,2"])  return@"iPhone 3G";

if([phoneType  isEqualToString:@"iPhone2,1"])  return@"iPhone 3GS";

if([phoneType  isEqualToString:@"iPhone3,1"])  return@"iPhone 4";

if([phoneType  isEqualToString:@"iPhone3,2"])  return@"iPhone 4";

if([phoneType  isEqualToString:@"iPhone3,3"])  return@"iPhone 4";

if([phoneType  isEqualToString:@"iPhone4,1"])  return@"iPhone 4S";

if([phoneType  isEqualToString:@"iPhone5,1"])  return@"iPhone 5";

if([phoneType  isEqualToString:@"iPhone5,2"])  return@"iPhone 5";

if([phoneType  isEqualToString:@"iPhone5,3"])  return@"iPhone 5c";

if([phoneType  isEqualToString:@"iPhone5,4"])  return@"iPhone 5c";

if([phoneType  isEqualToString:@"iPhone6,1"])  return@"iPhone 5s";

if([phoneType  isEqualToString:@"iPhone6,2"])  return@"iPhone 5s";

if([phoneType  isEqualToString:@"iPhone7,1"])  return@"iPhone 6 Plus";

if([phoneType  isEqualToString:@"iPhone7,2"])  return@"iPhone 6";

if([phoneType  isEqualToString:@"iPhone8,1"])  return@"iPhone 6s";

if([phoneType  isEqualToString:@"iPhone8,2"])  return@"iPhone 6s Plus";

if([phoneType  isEqualToString:@"iPhone8,4"])  return@"iPhone SE";

if([phoneType  isEqualToString:@"iPhone9,1"])  return@"iPhone 7";

if([phoneType  isEqualToString:@"iPhone9,2"])  return@"iPhone 7 Plus";

if([phoneType  isEqualToString:@"iPhone10,1"]) return@"iPhone 8";

if([phoneType  isEqualToString:@"iPhone10,4"]) return@"iPhone 8";

if([phoneType  isEqualToString:@"iPhone10,2"]) return@"iPhone 8 Plus";

if([phoneType  isEqualToString:@"iPhone10,5"]) return@"iPhone 8 Plus";

if([phoneType  isEqualToString:@"iPhone10,3"]) return@"iPhone X";

if([phoneType  isEqualToString:@"iPhone10,6"]) return@"iPhone X";

3、判断手机的系统版本:

NSString* systemVersion = [[UIDevice currentDevice] systemVersion];

ps:现在系统会自动提示:

if (@available(iOS 11.0, *)) {
     //
    }

请关注我的专题:iOS-Developer联盟 :https://www.jianshu.com/c/85ddda0d83de

    原文作者:guojieyhy
    原文地址: https://www.jianshu.com/p/e4299467fbcc
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞