iOS - 无法获得iphone SE和7的设备制造和型号

时间:2016-10-12 14:02:09

标签: ios iphone model

我使用以下代码来获取iOS设备型号,它适用于像5s这样的设备,但对于iPhone SE和iPhone 7等设备,它会进入异常状态并返回&#34; UIDeviceunknown&#34;。< / p>

- (NSUInteger) platformType
{
NSString *platform = [self platform];

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
NSLog(@"platform...%@",platform);
// The ever mysterious iFPGA
if ([platform isEqualToString:@"iFPGA"]) return UIDeviceIFPGA;

if ([platform isEqualToString:@"iPhone1,1"]) return UIDevice1GiPhone;
if ([platform isEqualToString:@"iPhone1,2"]) return UIDevice3GiPhone;
if ([platform hasPrefix:@"iPhone2"]) return UIDevice3GSiPhone;
if ([platform hasPrefix:@"iPhone3"]) return UIDevice4iPhone;
if ([platform hasPrefix:@"iPhone4"]) return UIDevice4SiPhone;
if ([platform hasPrefix:@"iPhone5,1"]) return UIDevice5iPhone;
if ([platform hasPrefix:@"iPhone5,2"]) return UIDevice5iPhone;
if ([platform hasPrefix:@"iPhone5,3"]) return UIDevice5CiPhone;
if ([platform hasPrefix:@"iPhone5,4"]) return UIDevice5CiPhone;
if ([platform hasPrefix:@"iPhone6"]) return UIDevice5SiPhone;
if ([platform hasPrefix:@"iPhone7,1"]) return UIDevice6PlusiPhone;
if ([platform hasPrefix:@"iPhone7,2"]) return UIDevice6iPhone;
if ([platform hasPrefix:@"iPhone8,1"]) return UIDevice6SiPhone;
if ([platform hasPrefix:@"iPhone8,2"]) return UIDevice6SPlusiPhone; 
if ([platform hasPrefix:@"iPhone8,4"]) return UIDeviceSEiPhone; 
if ([platform hasPrefix:@"iPhone9,1"]) return UIDevice7iPhone; 
if ([platform hasPrefix:@"iPhone9,2"]) return UIDevice7PlusiPhone; 
if ([platform hasPrefix:@"iPhone9,3"]) return UIDevice7iPhone; 
if ([platform hasPrefix:@"iPhone9,4"]) return UIDevice7PlusiPhone;
if ([platform hasPrefix:@"iPod1"]) return UIDevice1GiPod;
if ([platform hasPrefix:@"iPod2"]) return UIDevice2GiPod;
if ([platform hasPrefix:@"iPod3"]) return UIDevice3GiPod;
if ([platform hasPrefix:@"iPod4"]) return UIDevice4GiPod;
if ([platform hasPrefix:@"iPod5"]) return UIDevice5GiPod;
if ([platform hasPrefix:@"iPad1"]) return UIDevice1GiPad;
if ([platform hasPrefix:@"iPad2"]) return UIDevice2GiPad;
if ([platform hasPrefix:@"iPad3,1"]) return UIDevice3GiPad;
if ([platform hasPrefix:@"iPad3,2"]) return UIDevice3GiPad;
if ([platform hasPrefix:@"iPad3,3"]) return UIDevice3GiPad;
if ([platform hasPrefix:@"iPad3,4"]) return UIDevice4GiPad;
if ([platform hasPrefix:@"iPad3,5"]) return UIDevice4GiPad;
if ([platform hasPrefix:@"iPad3,6"]) return UIDevice4GiPad;
if ([platform hasPrefix:@"iPad4,1"]) return UIDeviceiPadAir;
if ([platform hasPrefix:@"iPad4,2"]) return UIDeviceiPadAir;
if ([platform hasPrefix:@"iPad4,3"]) return UIDeviceiPadAir;
if ([platform hasPrefix:@"iPad4,4"]) return UIDeviceiPadMini2;
if ([platform hasPrefix:@"iPad4,5"]) return UIDeviceiPadMini2;
if ([platform hasPrefix:@"iPad4,6"]) return UIDeviceiPadMini2;
if ([platform hasPrefix:@"AppleTV2"]) return UIDeviceAppleTV2;
if ([platform hasPrefix:@"AppleTV3"]) return UIDeviceAppleTV3;
if ([platform hasPrefix:@"iPhone"]) return UIDeviceUnknowniPhone; 
if ([platform hasPrefix:@"iPod"]) return UIDeviceUnknowniPod;
if ([platform hasPrefix:@"iPad"]) return UIDeviceUnknowniPad;
if ([platform hasPrefix:@"AppleTV"]) return UIDeviceUnknownAppleTV;


if ([platform hasSuffix:@"86"] || [platform isEqual:@"x86_64"])
{
    BOOL smallerScreen = [[UIScreen mainScreen] bounds].size.width < 768;
    return smallerScreen ? UIDevice6SiPhone:UIDevice6SiPhone ;
}
return UIDeviceUnknown;

}

1 个答案:

答案 0 :(得分:0)

Xcode 7在iPhone 7发布之前就已经发布了,所以是的,肯定会给UIDeviceUnknown带来同样的效果。

基础架构不受支持。即使您从Xcode 8获取iOS 10磁盘映像并将其放入Xcode 7中,即使这样也不能使其兼容并且在架构上能够检测到它。

简而言之,模拟器 - &gt;可能, 设备 - &gt;都能跟得上!

干杯! :)