Creating URL schemes

What we’ll be able to do when we’re done

At the end of this tutorial, we’ll be able to open an example app by typing “birdland://” into Safari for iOS.

Why this is important

Twitter Cards drives downloads to your iOS and Android applications. By configuring an URL scheme for your application, you can register a URL that Twitter can use to check to discover if the current user has your application installed. If it is, we can send users to a specific piece of content in the application through a process called “deep-linking”. If your app is not installed, we’ll use its iTunes application ID to send the user to the App Store to download it.

How to implement

Step 1 - Create our application

Open Xcode. Go to File → New, and create a new Single View Application.

image0

We need to configure our application to tell the system what scheme we support. In this example, we want to register “birdland”.

image1

Step 2 - Configure our Xcode project

Next, we need to define our custom URL type. Remember, we want to open the app via “birdland://”, so that will be our URL scheme. We also need to assign an unique identifier to the scheme. Apple recommends that you use reverse DNS notation to ensure that there are no name collisions on the platform, so we’ll use “com.mycompany.ios” for this example.

image2

That’s it! You’ve configured the app with simple support for the URL scheme “birdland://”. There is, of course, much more that you can do with Custom URL Schemes. To find out more, check out Apple’s documentation.

Verify that everything works

Run the Xcode project in the iOS Simulator. When the application starts, you should just see a white screen in the Simulator since we have an empty app.

image3
Empty application is empty

Now, to check that our registered URL scheme works, we’ll head out to Safari. Press the “Home” button in the Simulator (or press command-shift-H) to reach the Home Screen. Open Safari.

Next, type “birdland://” in the address bar of Safari. Just as we can with http:// URLs, we’re asking Safari to open the “birdland” scheme. Press Go.

image4
Open our app via Safari

You should see that we’ve arrived back at our white screen in our example project.

Applying this tutorial to your application

To use these steps for your application, just determine the scheme that you would like to use to open your application and replace the “birdland” that we used in Step 2 with the scheme.

Next, we’ll discuss how to handle URL schemes to deep-link users into your application’s content.