使用 UI_USER_INTERFACE_IDIOM() 进行区分 (ios 3.2 >=) 无法区分iphone和ipod if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { // <define your constants here> } else { // <define your constants here> } 区分目前UI_USER_INTERFACE_IDIOM()有2个返回值 UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone 使用 UIDevice.model 进行区分 (ios 2.0 >=) NSString *deviceType = [UIDevice currentDevice].model; if([deviceType isEqualToString:@"iPhone"]) { //iPhone } else if([deviceType isEqualToString:@"iPod touch"]) { //iPod Touch } else { //iPad } 使用系统的一个函数sysctlbyname 来获取设备名称 - (NSString *) platformString { size_t size; sysctlbyname("hw.machine", NULL, &size, NULL, 0); char *machine = malloc(size); sysctlbyname("hw.machine", machine, &size, NULL, 0); NSString *platform = [NSString stringWithUTF8String:machine]; free(machine); 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:@"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:@"i386"]) return @"Simulator"; return @""; } 在添加一些收集到的 //iPhone if ([deviceString isEqualToString:@"iPhone4,1"]) return @"iPhone 4S"; if ([deviceString isEqualToString:@"iPhone5,1"]) return @"iPhone 5(AT&T)"; if ([deviceString isEqualToString:@"iPhone5,2"]) return @"iPhone 5(GSM/CDMA)"; //iPod Touch if ([deviceString isEqualToString:@"iPod5,1"]) return @"iPod Touch 5G"; //iPad if ([deviceString isEqualToString:@"iPad2,5"]) return @"iPad Mini (WiFi)"; if ([deviceString isEqualToString:@"iPad2,6"]) return @"iPad Mini (GSM)"; if ([deviceString isEqualToString:@"iPad2,7"]) return @"iPad Mini (CDMA)"; if ([deviceString isEqualToString:@"iPad3,1"]) return @"iPad 3 (WiFi)"; if ([deviceString isEqualToString:@"iPad3,2"]) return @"iPad 3 (GSM)"; if ([deviceString isEqualToString:@"iPad3,3"]) return @"iPad 3 (CDMA)"; if ([deviceString isEqualToString:@"iPad3,4"]) return @"iPad 4 (WiFi)"; if ([deviceString isEqualToString:@"iPad3,5"]) return @"iPad 4 (GSM)"; if ([deviceString isEqualToString:@"iPad3,6"]) return @"iPad 4 (CDMA)"; //Simulator if ([deviceString isEqualToString:@"i386"]) return @"Simulator"; if ([deviceString isEqualToString:@"x86_64"]) return @"Simulator"; 转载的没有那么多个机型逐个实验.所以不敢保证都正确.
原出处:http://blog.sina.com.cn/s/blog_890a737301014fim.html