1

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
spinalwrap
  • 683
  • 1
  • 4
  • 17
  • 6
    Detect the model number and then based on that you know if it has one or the other. http://stackoverflow.com/questions/11197509/ios-iphone-get-device-model-and-make – CW0007007 Aug 26 '14 at 12:34
  • is there a better way to do this than parsing the e.g. "iPad 3,4" strings? this will have to be updated each time new devices are released. – spinalwrap Aug 26 '14 at 12:36
  • Depends, what are you trying to achieve by knowing what the charger is ? – CW0007007 Aug 26 '14 at 12:37
  • I want to display UI which tells the user whether you need the old 30-pin CCK or the new Lightning-to-USB adapter, and link to the relevant page in the Apple shoppe. this: http://store.apple.com/us/product/MC531ZM/A/apple-ipad-camera-connection-kit vs this: http://store.apple.com/us/product/MD821ZM/A/lightning-to-usb-camera-adapter – spinalwrap Aug 26 '14 at 12:39
  • please give the answer of my question http://stackoverflow.com/questions/30617946/support-only-lightening-device-in-ios – Ravi Ojha Jun 03 '15 at 10:59

1 Answers1

1

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;
}
Community
  • 1
  • 1
spinalwrap
  • 683
  • 1
  • 4
  • 17