适用于iPhone 4S和iPhone 5的设备类型文本

时间:2012-11-28 13:16:27

标签: iphone ios

以下代码的输出是什么:

NSString *deviceType = [UIDevice currentDevice].model;
NSLog(@"Device Type: %@", deviceType);
在iPhone 4中,它会打印“iPhone”,但在iPhone 4S或iPhone 5中会输出什么?我没有iPhone 4S或5设备。但我需要知道它在所有版本的iPhone中实现调用功能。

感谢。

3 个答案:

答案 0 :(得分:3)

  在iPhone 4中,它会打印“iPhone”,但在iPhone 4S或iPhone 5中会输出什么?

也是“iPhone”。

documentation。)

答案 1 :(得分:1)

UIDevice没有用?

#include <sys/types.h>
#include <sys/sysctl.h>

- (NSString *)deviceModel
{
    NSString *deviceModel = nil;
    char buffer[32];
    size_t length = sizeof(buffer);
    if (sysctlbyname("hw.machine", &buffer, &length, NULL, 0) == 0) {
        deviceModel = [[NSString alloc] initWithCString:buffer encoding:NSASCIIStringEncoding];
    }
    return [deviceModel autorelease];
}

我也不知道5的常数,但我知道它们是唯一的:

if ([platform isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";
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,3"])    return @"Verizon iPhone 4";
if ([platform isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
if ([platform isEqualToString:@"iPod1,1"])      return @"iPod Touch 1G";
if ([platform isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";
if ([platform isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";
if ([platform isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";
if ([platform isEqualToString:@"iPad1,1"])      return @"iPad";
if ([platform isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
if ([platform isEqualToString:@"iPad2,2"])      return @"iPad 2 (GSM)";
if ([platform isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
if ([platform isEqualToString:@"iPad2,4"])      return @"iPad 2";
if ([platform isEqualToString:@"iPad3,1"])      return @"iPad-3G (WiFi)";
if ([platform isEqualToString:@"iPad3,2"])      return @"iPad-3G (4G)";
if ([platform isEqualToString:@"iPad3,3"])      return @"iPad-3G (4G)";
if ([platform isEqualToString:@"i386"])         return @"Simulator";
if ([platform isEqualToString:@"x86_64"])       return @"Simulator";

电话5 GSM - iPhone5,1

iPhone 5 CDMA - iPhone5,2

iPod 5 - iPod5,1

从iOS文件名中获取的信息。请检查http://osxdaily.com/2012/09/19/ios-6-ipsw-direct-download-links/

答案 2 :(得分:0)

如果你想区分iPhone4 / 4S&amp; iPhone5,您应该检查屏幕尺寸,而不是设备型号。