1

I am using the following code to get the iOS device model, it works for devices like 5s but for some devices like iPhone SE and iPhone 7 it goes into the exception condition and returns "UIDeviceunknown".

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

}
Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69
  • Do you use Xcode 8? – kamwysoc Oct 12 '16 at 14:05
  • @k8mil using Xcode 7 – Kartikeya Khosla Oct 12 '16 at 14:16
  • I've tested on Xcode7 and my iPhone7 and use this code to print model : http://stackoverflow.com/a/30075200/5433235 and I received Iphone9,3. In your code iPhone 7 should return iPhone9,1 – kamwysoc Oct 12 '16 at 14:19
  • @k8mil thanks, I will recheck, maybe its something further down the line in my code, I wasn't able to test with iPhone 7 but was dependent on live users records in Database which seemed to suggest this issue with iphone 7 but on iphone SE i did check and it went into the unknown device condition. – Kartikeya Khosla Oct 12 '16 at 14:40

1 Answers1

0

Xcode 7 was released way before iPhone 7 was released so yeah it would definitely give UIDeviceUnknown for the same.

Base architecture won't be supported. Even after you take the iOS 10 disk image from Xcode 8 and put it inside Xcode 7, even that doesn't make it compatible and architecturally capable to detect the same.

So in short, Simulator -> Possible, Device -> Nope!

Cheers! :)

Annie Gupta
  • 2,786
  • 15
  • 23