Launching iOS app from Custom URL Scheme

If I launch my iOS app from a Custom URL Scheme it immediately crashes, without even running my code (i.e. before entering at main()). Xcode is reporting this:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application has LSSupportsOpeningDocumentsInPlace' key, but doesn't implement application:openURL:options: on delegate <SDLUIKitDelegate: 0x283c9c3a0>'.

So it looks like the SDL2 framework for iOS is not allowing for the app being opened from a Custom URL Scheme when Supports opening documents in place is enabled (which I need).

Is this something that is easily fixable?

And indeed in SDL_uikitappdelegate.m there’s this:

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
    /* TODO: Handle options */
    [self sendDropFileForURL:url];
    return YES;

So this seems to be a known omission. How long has that TODO been there, and when might it get DONE?!

The problem is that iOS thinks the app delegate doesn’t implement the -application:openURL:options: function, however it’s clearly there in SDL_uikitappdelegate.m. Objective-C uses dynamic dispatch, so it’s not checking to see if -application:openURL:options: does anything (which it does), but simply if it even exists.

Looking at the source, there’re some version guards surrounding it. Is your app’s Deployment Target set to iOS 9.0 or later?

As implemented, -application:openURL:options: is just taking the given URL and passing it along to the application as if a file was drag & dropped onto its window on a desktop machine.

It’s set to iOS 12.0 in Xcode, but SDL2 is being built separately at the command line (using the script which I didn’t write) so is it possible that the target wasn’t set correctly in that build? I don’t see anything in the script that explicitly does that.

That does seem to be exactly the problem. I had long ago changed the Deployment Target for my app’s build to iOS 12.0, but I hadn’t subsequently rebuilt the SDL2 library itself (nor SDL2_ttf and SDL2_net).

Arguably that’s a weakness of building libraries rather than bundling the SDL2 sources into my own project (although I might have hoped Xcode could check consistency of deployment target across libraries).

Thanks for the help, I would never have figured it out otherwise.

1 Like