码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 版本信息 包含6,6plus

时间:2015-01-27 18:24:14      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:ios

导入#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

iOS 版本信息 包含6,6plus

标签:ios

原文地址:http://blog.csdn.net/qq_16855025/article/details/43197423

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!