获取手机型号iphoneX 、iphoneXR、iphone XS、iphone XS MAX

-(NSString *)getCurrentDeviceModel

{

    int mib[2];

    size_t len;

    char *machine;

    

    mib[0] = CTL_HW;

    mib[1] = HW_MACHINE;

    sysctl(mib, 2, NULL, &len, NULL, 0);

    machine = malloc(len);

    sysctl(mib, 2, machine, &len, NULL, 0);

    NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];

    free(machine);

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

    if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G (A1241/A1324)";

    if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS (A1303/A1325)";

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

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

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

    if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S (A1387/A1431)";

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

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

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

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

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

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

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

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

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

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

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

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

    if ([platform isEqualToString:@"iPhone9,3"]) return @"iPhone 7";

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

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

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

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

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

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

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

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

    if ([platform isEqualToString:@"iPhone11,8"]) return @"iPhone XR";

    if ([platform isEqualToString:@"iPhone11,2"]) return @"iPhone XS";

    if ([platform isEqualToString:@"iPhone11,4"]) return @"iPhone XS Max";

    if ([platform isEqualToString:@"iPhone11,6"]) return @"iPhone XS Max";

    

    

    if ([platform isEqualToString:@"i386"])      return @"iPhone Simulator";

    if ([platform isEqualToString:@"x86_64"])    return @"iPhone Simulator";

    

    return platform;

}

你可能感兴趣的:(获取手机型号iphoneX 、iphoneXR、iphone XS、iphone XS MAX)