I need to detect whether an iOS device is equipped with a Lightning port or the vintage 30-pin port.
What is the most reliable way to do so?
I need to detect whether an iOS device is equipped with a Lightning port or the vintage 30-pin port.
What is the most reliable way to do so?
using this to get the device model string: iOS - How to get device make and model?
then doing manual heuristic to decide on the port that's used. This is assuming that future iOS devices will have a Lightning port, and that the numbers in the machine name will follow the same model as up until now (August 2014)
NSString *machineName()
{
struct utsname systemInfo;
uname(&systemInfo);
return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}
NS_ENUM(NSUInteger, MachineConnectorType)
{
MachineConnectorTypeUnknown,
MachineConnectorType30Pin,
MachineConnectorTypeLightning
};
enum MachineConnectorType MachineConnectorTypeWithMachineName(NSString *machineName)
{
if([machineName rangeOfString:@"iPad"].location != NSNotFound)
{
// 1st gen mini wants to be special
if([machineName isEqualToString:@"iPad2,5"])
{
return MachineConnectorTypeLightning;
}
NSString *model = [machineName substringFromIndex:4];
if(model.intValue >= 3)
return MachineConnectorTypeLightning;
return MachineConnectorType30Pin;
}
else if ([machineName rangeOfString:@"iPod"].location != NSNotFound)
{
NSString *model = [machineName substringFromIndex:4];
if(model.intValue >= 5)
return MachineConnectorTypeLightning;
return MachineConnectorType30Pin;
}
else if ([machineName rangeOfString:@"iPhone"].location != NSNotFound)
{
NSString *model = [machineName substringFromIndex:6];
if(model.intValue >= 5)
return MachineConnectorTypeLightning;
return MachineConnectorType30Pin;
}
return MachineConnectorTypeUnknown;
}