iosxcodeios10.3ios11

Supporting older versions of iOS


I am developing a new iOS app, that is supposed to support the new drag and drop feature (iOS 11) out of the box. However I want it to be executable on older (iOS 10) devices as well. As I understand it setting the Deployment Target to iOS 11 will prevent the app from being installed on older devices. However setting it down to iOS 10.3 will cause errors to appear, stating that Drag and Drop is only available on iOS 11.0 or newer.

My question is: Is there a way I can make the app available to older devices by either providing two versions (one with DnD, one without for legacy) or tell xcode to ignore the DnD lines for older versions? Or is this just simply impossible?

All help is appreciated!


Solution

  • Move all your delegate conformances to extensions, and then add @available attribute to the extensions. For example:

    @available(iOS 11.0, *)
    extension DragBoardViewController : UIDragInteractionDelegate { ... }
    

    If you write these conformances as extensions, Xcode 9 will automatically give you fix-its to add the @available attribute.

    Remember, you absolutely can have these delegate methods defined in iOS 10; they just won't be called. The point of @available is to prevent other parts of the code from calling this without first wrapping it in an #available check.

    A nice way to explore this is to download Apple's sample code and then just set the deployment target to 10.0. You'll see lots of fix-its pop up to help you through the process and show how to do it in your own code.