1

我试图找出一种简单的方法来了解我的Device类型。

我已经知道了

  [[UIDevice currentDevice] systemVersion]

这给了我一般类型。

但我真正需要的是现在它是 4、4S、5 还是任何其他类型的iPhone.

4

4 回答 4

7

您可以使用此方法获取您的平台和设备类型

- (NSString *) platformString{
    // Gets a string with the device model
    size_t size;  
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);  
    char *machine = malloc(size);  
    sysctlbyname("hw.machine", machine, &size, NULL, 0);  
    NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];  
    free(machine); 
    if ([platform isEqualToString:@"iPhone1,1"])    return @"iPhone 2G";
    if ([platform isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
    if ([platform isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
    if ([platform isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
    if ([platform isEqualToString:@"iPhone3,2"])    return @"iPhone 4";
    if ([platform isEqualToString:@"iPhone3,3"])    return @"iPhone 4 (CDMA)";    
    if ([platform isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
    if ([platform isEqualToString:@"iPhone5,1"])    return @"iPhone 5";
    if ([platform isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (GSM+CDMA)";

    if ([platform isEqualToString:@"iPod1,1"])      return @"iPod Touch (1 Gen)";
    if ([platform isEqualToString:@"iPod2,1"])      return @"iPod Touch (2 Gen)";
    if ([platform isEqualToString:@"iPod3,1"])      return @"iPod Touch (3 Gen)";
    if ([platform isEqualToString:@"iPod4,1"])      return @"iPod Touch (4 Gen)";
    if ([platform isEqualToString:@"iPod5,1"])      return @"iPod Touch (5 Gen)";

    if ([platform isEqualToString:@"iPad1,1"])      return @"iPad";
    if ([platform isEqualToString:@"iPad1,2"])      return @"iPad 3G";
    if ([platform isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
    if ([platform isEqualToString:@"iPad2,2"])      return @"iPad 2";
    if ([platform isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
    if ([platform isEqualToString:@"iPad2,4"])      return @"iPad 2";
    if ([platform isEqualToString:@"iPad2,5"])      return @"iPad Mini (WiFi)";
    if ([platform isEqualToString:@"iPad2,6"])      return @"iPad Mini";
    if ([platform isEqualToString:@"iPad2,7"])      return @"iPad Mini (GSM+CDMA)";
    if ([platform isEqualToString:@"iPad3,1"])      return @"iPad 3 (WiFi)";
    if ([platform isEqualToString:@"iPad3,2"])      return @"iPad 3 (GSM+CDMA)";
    if ([platform isEqualToString:@"iPad3,3"])      return @"iPad 3";
    if ([platform isEqualToString:@"iPad3,4"])      return @"iPad 4 (WiFi)";
    if ([platform isEqualToString:@"iPad3,5"])      return @"iPad 4";
    if ([platform isEqualToString:@"iPad3,6"])      return @"iPad 4 (GSM+CDMA)";

    if ([platform isEqualToString:@"i386"])         return @"Simulator";
    if ([platform isEqualToString:@"x86_64"])       return @"Simulator";
    return platform;
}
于 2013-01-01T07:45:28.947 回答
1

您好使用此类从以下链接获取设备类型和设备版本..

UIDevice硬件

只需阅读如何使用以及如何获取平台的说明...

在这里,您得到了类似示例的响应... Verizon iPhone 4、iPhone 4S、iPod Touch 1G、iPod Touch 2G 等。

我希望这对你有帮助......

于 2013-01-01T07:36:05.610 回答
1

我用当前可用的设备更新了列表。我建议在 上做一个类别UIDevice,我们称之为UIDevice+Platform,并添加以下两个方法:

- (NSString *)rawPlatform
{
    static NSString *platform = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        size_t size;
        sysctlbyname("hw.machine", NULL, &size, NULL, 0);
        char *machine = malloc(size);
        sysctlbyname("hw.machine", machine, &size, NULL, 0);
        platform = [NSString stringWithUTF8String:machine];
        free(machine);
    });
    return platform;
}

- (NSString *)exactModel
{
    static NSString *platform = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        platform = [self rawPlatform];
        if ([platform isEqualToString:@"iPhone1,1"])
            platform = @"iPhone 1G";
        else if ([platform isEqualToString:@"iPhone1,2"])
            platform = @"iPhone 3G";
        else if ([platform isEqualToString:@"iPhone2,1"])
            platform = @"iPhone 3GS";
        else if ([platform isEqualToString:@"iPhone3,1"])
            platform = @"iPhone 4";
        else if ([platform isEqualToString:@"iPhone3,3"])
            platform = @"Verizon iPhone 4";
        else if ([platform isEqualToString:@"iPhone4,1"])
            platform = @"iPhone 4S";
        else if ([platform isEqualToString:@"iPhone5,1"])
            platform = @"iPhone 5";
        else if ([platform isEqualToString:@"iPhone5,2"])
            platform = @"iPhone 5 (GSM+CDMA)";
        else if ([platform isEqualToString:@"iPhone5,3"])
            platform = @"iPhone 5C";
        else if ([platform isEqualToString:@"iPhone5,4"])
            platform = @"iPhone 5C (GSM+CDMA)";
        else if ([platform isEqualToString:@"iPhone6,1"])
            platform = @"iPhone 5S";
        else if ([platform isEqualToString:@"iPhone6,2"])
            platform = @"iPhone 5S (GSM+CDMA)";
        else if ([platform isEqualToString:@"iPhone7,1"])
            platform = @"iPhone 6+";
        else if ([platform isEqualToString:@"iPhone7,2"])
            platform = @"iPhone 6";
        else if ([platform isEqualToString:@"iPod1,1"])
            platform = @"iPod Touch 1G";
        else if ([platform isEqualToString:@"iPod2,1"])
            platform = @"iPod Touch 2G";
        else if ([platform isEqualToString:@"iPod3,1"])
            platform = @"iPod Touch 3G";
        else if ([platform isEqualToString:@"iPod4,1"])
            platform = @"iPod Touch 4G";
        else if ([platform isEqualToString:@"iPod5,1"])
            platform = @"iPod Touch 5G";
        else if ([platform isEqualToString:@"iPad1,1"])
            platform =  @"iPad 1";
        else if ([platform isEqualToString:@"iPad2,1"])
            platform = @"iPad 2 (WiFi)";
        else if ([platform isEqualToString:@"iPad2,2"])
            platform =  @"iPad 2 (GSM)";
        else if ([platform isEqualToString:@"iPad2,3"])
            platform = @"iPad 2 (CDMA)";
        else if ([platform isEqualToString:@"iPad2,1"])
            platform = @"iPad 2 (WiFi)";
        else if ([platform isEqualToString:@"iPad2,2"])
            platform =  @"iPad 2 (GSM)";
        else if ([platform isEqualToString:@"iPad2,3"])
            platform = @"iPad 2 (CDMA)";
        else if ([platform isEqualToString:@"iPad2,4"])
            platform = @"iPad 2";
        else if ([platform isEqualToString:@"iPad2,5"])
            platform = @"iPad Mini (Wifi)";
        else if ([platform isEqualToString:@"iPad2,6"])
            platform = @"iPad Mini";
        else if ([platform isEqualToString:@"iPad2,7"])
            platform = @"iPad Mini (GSM+CDMA)";
        else if ([platform isEqualToString:@"iPad3,1"])
            platform = @"iPad 3 (WiFi)";
        else if ([platform isEqualToString:@"iPad3,2"])
            platform = @"iPad 3 (GSM+CDMA)";
        else if ([platform isEqualToString:@"iPad3,3"])
            platform = @"iPad 3 (4G,3)";
        else if ([platform isEqualToString:@"iPad3,4"])
            platform = @"iPad 4 (WiFi)";
        else if ([platform isEqualToString:@"iPad3,5"])
            platform = @"iPad 4 (4G,2)";
        else if ([platform isEqualToString:@"iPad3,6"])
            platform = @"iPad 4 (GSM+CDMA)";
        else if ([platform isEqualToString:@"iPad4,1"])
            platform = @"iPad Air (Wifi)";
        else if ([platform isEqualToString:@"iPad4,2"])
            platform = @"iPad Air (GSM+CDMA)";
        else if ([platform isEqualToString:@"iPad4,3"])
            platform = @"iPad Air";
        else if ([platform isEqualToString:@"iPad4,4"])
            platform = @"iPad Mini 2 (GSM)";
        else if ([platform isEqualToString:@"iPad4,5"])
            platform = @"iPad Mini 2 (CDMA)";
        else if ([platform isEqualToString:@"iPad4,6"])
            platform = @"iPad Mini 2 (Wifi)";
        else if ([platform isEqualToString:@"iPad4,7"])
            platform = @"iPad Mini 3 (Wifi)";
        else if ([platform isEqualToString:@"iPad4,8"])
            platform = @"iPad Mini 3 (GSM+CDMA)";
        else if ([platform isEqualToString:@"iPad4,9"])
            platform = @"iPad Mini 3";
        else if ([platform isEqualToString:@"iPad5,3"])
            platform = @"iPad Air 2 (Wifi)";
        else if ([platform isEqualToString:@"iPad5,4"])
            platform = @"iPad Air 2 (GSM+CDMA)";
        else if ([platform isEqualToString:@"i386"])
            platform = @"Simulator";
        else if ([platform isEqualToString:@"x86_64"])
            platform = @"Simulator";
    });

    return platform;
}
于 2015-02-07T16:23:58.203 回答
0

UIDeviceClass a 属性中找出 iPhone 的类型:

@property(nonatomic,readonly,retain) NSString    *systemVersion;     // e.g. @"4.0"
于 2013-01-01T07:35:42.673 回答