2016-10-12 6 views
1

次のコードを使用してiOSデバイスモデルを取得しています。これは5sなどのデバイスで動作しますが、iPhone SEやiPhone 7などのデバイスでは例外条件を返し、 "UIDeviceunknown"を返します。iOS - iphone SEと7のデバイス製造元とモデルを取得できません

- (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; 

} 
+0

Xcode 8を使用していますか? – kamwysoc

+0

@ k8mil using Xcode 7 –

+0

私はXcode7と私のiPhone7でテストし、このコードを使ってモデル番号 http://stackoverflow.com/a/30075200/5433235 を受け取り、Iphone9,3を受け取った。あなたのコードでiPhone 7はiPhone9,1を返します。 – kamwysoc

答えて

0

Xcodeの7は、iPhone 7がそうええ、それは間違いなく同じためUIDeviceUnknownを与えるだろうリリースされたの前に道をリリースしました。

基本アーキテクチャはサポートされません。 Xcode 8からiOS 10ディスクイメージを取り出してXcode 7に入れても、互換性がなく、構造的に同じものを検出することはできません。

つまり、Simulator - > Possible、 Device - > Nope!

乾杯! :)

+0

ありがとう、私は私のXcodeを更新し、結果をポストします –

関連する問題