Search code examples
iosuiapplicationdelegate

What is the options argument in the AppDelegate's application:openURL:options: method?


I searched the web up and down but could not find one example. Apple's docs says it is to define launch options. But what are these? What would be a harmless/basic option to include?


Solution

  • From the Apple docs on UIApplicationDelegate:

    Open a URL that was sent to your app. If there is a URL to open, the system calls the application:openURL:options: method of your app delegate. You can also tell if there is a URL to open by looking in the launch options dictionary for the UIApplicationLaunchOptionsURLKey key.

    Therefore, the options parameter is for the system to provide, when your app is being opened with a URL that has been sent to it. You don't have to pass anything when you call it, so you can just provide an empty dictionary for the options if you're just using it to open an external URL (although you may want to pass your bundle ID for the UIApplicationLaunchOptionsSourceApplicationKey key).

    EDIT

    Thinking about it further, this is completely the wrong way of opening an external URL from your app. It's just a delegate method for the system to call to allow your app to open a URL (like from the Safari action sheet). You want:

    [[UIApplication sharedApplication] openURL:url];