iOS 版本信息 包含6,6plus

导入#import <sys/sysctl.h>

/**

 * iPhone的设备号
 **/
+ (NSString *)iPhoneVersion
{
    NSString *iPhoneVersion = nil;
    
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = (char*)malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
    free(machine);
    
    if ([platform isEqualToString:@"iPhone1,1"]) {
        iPhoneVersion = @"iPhone";
    }
    if ([platform isEqualToString:@"iPhone1,2"]) {
        iPhoneVersion = @"iPhone 3G";
    }
    if ([platform isEqualToString:@"iPhone2,1"]) {
        iPhoneVersion = @"iPhone 3GS";
    }
    if ([platform isEqualToString:@"iPhone3,1"] || [platform isEqualToString:@"iPhone3,2"] || [platform isEqualToString:@"iPhone3,3"]) {
        iPhoneVersion = @"iPhone 4";
    }
    if ([platform isEqualToString:@"iPhone4,1"]) {
        iPhoneVersion = @"iPhone 4S";
    }
    if ([platform isEqualToString:@"iPhone5,1"] || [platform isEqualToString:@"iPhone5,2"]) {
        iPhoneVersion = @"iPhone 5";
    }
    if ([platform isEqualToString:@"iPhone5,3"] || [platform isEqualToString:@"iPhone5,4"]) {
        iPhoneVersion = @"iPhone 5c";
    }
    if ([platform isEqualToString:@"iPhone6,1"] || [platform isEqualToString:@"iPhone6,2"]) {
        iPhoneVersion = @"iPhone 5s";
    }
    if ([platform isEqualToString:@"iPhone7,2"]) {
        iPhoneVersion = @"iPhone 6";
    }
    if ([platform isEqualToString:@"iPhone7,1"]) {
        iPhoneVersion = @"iPhone 6Plus";
    }
    
    return iPhoneVersion;

}


更多标签对比:http://theiphonewiki.com/wiki/Models

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。