Getting StartedTurnpike was developed by URX to enable mobile deeplinking in apps. Turnpike’s Core Responsibilities
Mobile Deeplinking with TurnpikeTurnpike lets you map deeplink URI routes to in-app actions.
Turnpike allows the creation of filters to centralize the processing logic for incoming requests.
After filter processing, Turnpike resolves route requests to their final in-app destinations.
First Steps with TurnpikeThe Turnpike SDK can be obtained via GitHub, and we recommend keeping Turnpike updated via Git. The next step is to enable deeplinking within your app <enabling-mobile-deeplinking>, and integrate Turnpike at the deeplink entry point. Next, feel free to read on below about Turnpike’s capabilities! Turnpike Request LifecycleWhen resolving deeplink URI’s, Turnpike takes the following steps:
InstallationThis installation tutorial will show you how to add URX Turnpike to an existing project, and how to keep it up-to-date. PrerequisiteWith Turnpike, we’ll be using Git to manage versions. If you haven’t used Git before, we recommend running through a quick Git tutorial. You must have Git installed to complete this tutorial. Step 1: Add your Project to WorkspaceNote: You may skip to step two if you are already developing your App in a workspace. Starting with Xcode 4, Apple introduced the concept of Workspace management. This took the prior concept of Project Management, and allowed encapsulated projects, and shared documents, to exist in a space together so you can work on, and reference them, simultaneously. Projects in a Workspace also share a build directory, making it easy to link to binaries of projects in the workspace. To start, create a folder to house our workspace. Because my app is called In Xcode, Go to File->New->Workspace, or press Control + Command + N, to create a new Workspace, and save it in the folder we just created with the name of your Workspace. Now that you have a Workspace, we need to put some projects into it! Lets start with your existing project. Before we add it to the Workspace in Xcode, let’s move the project folder into the Workspace folder, just to keep the organization cleaner and not have your Workspace’s managed projects all over the place Go to File->New->Add Files to “TestAppWorkspace” (where “TestAppWorkspace” is your workspace), or press Option + Command + A, and you’ll be able to select files. Navigate to your App’s Step 2: Add Turnpike to WorkspaceNow that you have your project in a workspace, open your Terminal and navigate to your Workspace folder. Once there, run Note: If you have already submoduled a version of Turnpike, skip to the last step on maintenance to update it before continuing. Next we need to add the Turnpike project as we did for our own App, so in Xcode, go to File->New->Add Files to “TestAppWorkspace” (where “TestAppWorkspace” is your workspace), or press Option + Command + A, and this time select Step 3: Test & Compile TurnpikeFirst we want to compile Turnpike into a binary. On the top bar of the editor window, under “Scheme”, select “Turnpike”, and select a simulator to run on. Try giving the tests a run (Command + U), and the console should report that everything ran fine. Although running the test involved Build Phases, we didn’t get a binary from it, as evidenced by expanding the Products group in the Turnpike project, and seeing that With static libraries, like Turnpike, tests can only be performed on the simulator, while binaries can only be compiled by targeting actual device architecture, so select “iOS Device” under Turnpike’s schema (“iOS Device” may have the name of your iOS device if it’s plugged into your computer), and build Turnpike (Command + B). Step 4: Linking to Turnpike Binary and HeadersThis next part is a little more complicated, but follow along, and it’ll be easy. Now that it’s built we need to tell our own App to use Turnpike. First lets point to Turnpike’s headers so Xcode can know about them and not get upset when we claim they exist. In Xcode, click on your project settings, and select your “Project” (not “Target”). Select the “Build Settings” tab and in the search field, search for “User Header Search Paths”. You should see “User Header Search Paths” show up. Double click on the rightmost portion of this row to bring up a box with little + and - buttons. Hit the + button and type Next, in your project settings, select your “Target”, and select the “Build Phases” tab. In your “Link Binary With Libraries” phase, hit the + button and select Step 5: Adding a Custom URL SchemeIf your app doesn’t yet have a custom URL scheme you’ll need to have your app register for one on the user’s device. Fortunately, this is now easier than ever in Xcode. In your app’s project settings, select your “Target”, and click on the info tab. There, you should expand the “URL Types” section. If you already have a custom URL registered, you’ll see it there, and if not, this will be empty and say “No URL Types”. Click the + button to create a new URL Type. Most of this is not important to us, as it deals with file handling. What is important is the Identifier and URL Schemes fields. For both these fields, you want to enter your App’s Bundle Identifier in reverse domain name style. This is recommended practice by Apple (although even they are guilty of not doing this in their sample app) as behavior for collisions is undefined. You can find your bundle identifier by switching to the “Summary” tab in your “Target”. Note: Even if you already have a URL schema registered, we recommend you register one in the reverse domain name style and use that one for creating deep links. This will prevent any non-malicious collisions, and is what we recommend as best practice. Step 6: Setting up Turnpike in your AppThe hard part is all finished, now you just need to tell your app what routes you want to register and when to invoke a route. Open up your In your
The last thing we have to do is let Turnpike pick up the incoming URL. To do this, we’ll need our AppDelegate to implement Note:
In your Congratulations, you have now added Deeplinking to your app! Step 7: Feel the Magic (Make sure it works)Lets do a quick test to make sure it works. Build and Run your app on the simulator or your device. Go to Safari and enter your URL Schema + “:hello” and hit “Go”. For my app this is “ Note: this could also be com.urx.TestApp://hello, com.urx.TestApp:///hello or just com.urx.TestApp:hello. Leading slashes after the colon are ignored, and the route in this case, is just hello. This should quickly switch to your app and in your Xcode console, you should see hello world. Congratulations, you’ve integrated URX Turnpike! Time for cookies! Bonus Step: Keeping Up-To-Date with URX TurnpikeUpdating Turnpike is easy! Just open up your console, navigate to your Turnpike directory, then run After updating, make sure to re-build your Turnpike binary in Xcode. Select Turnpike from the scheme list, and make sure you’re building for “iOS Device” (or the name of the device you have plugged into your computer). Press Command + B to build, and you’re all updated! Enabling Mobile DeeplinkingCustom URL SchemesTo register a URL schema, add the CFBundleURLTypes key to your app’s Info.plist file. CFBundleURLTypes contains an array of dictionaries, each of which defines a URL scheme the app supports. Each dictionary within the array is a key / value pair of CFBundleURLName (string) and CFBundleURLSchemes (array of strings). The CFBundleURLName should be, according to Apple, in reverse dns format
( The CFBundleURLSchemes is an array of custom URL schemas you want your app to respond to. You can add as many as you like, but you only need one. Implementing handleOpenURLIn the your’s App Delegate, you must implement the optional App Delegate method that allow your app to perform deeplinking. This method is:
In your implementation of this method, you should resolve the incoming
url your router. If you’re using Turnpike’s shared router (which is all
that’s needed in most cases), simply call Mapping Routes to DestinationsTurnpike can map routes to Destinations <mr-assigning-destinations>. Destinations represent where to navigate and/or what action to take upon a user’s entry into an app via deeplink URI. Turnpike supports many mapped routes <mr-mapped-routes> and one default route <mr-default-route>. Default RouteTo define a Default Route, use the method The Default Route is invoked when no route is matched. By default, this does nothing and just launches your app.
Mapped RoutesMapped routes are one of: - Static:
Assigning Destinations to RoutesFor example, if a resolved deeplink should push a Product Page onto our UINavigation Controller, we might use a callback like this:
Using Dynamic RoutesIn the case of dynamic routes, route parameters can be accessed in the
filter or callback through the
Suppose we want the links
Route RequestsRoute Requests hold data about the in-app session created as a user enters an app from a deeplink URI. Requests have a lifecycle consisting of 3 stages:
The Deeplink MetadataThe
Two of
For instance:
The Route Request CreationDuring Request Creation, a After route matching, the
The Filters & Filter ChainsFilters allow you to perform logic with the incoming Route Request before the route’s mapped destination is resolved. Filters can be used for authentication, redirecting, analytics, and more. Turnpike’s implementation of filters uses a simplified version of the intercepting filter pattern.
Filters are processed sequentially in a
Filter Chain <fc-filter-chain>. Each Filters can either be added to the filter chain in one of two ways:
FiltersImplementing a FilterFilters themselves are objects that respond to
This is the method that is used to process a
Processing Query Parameters with a Filter
Anonymous FiltersThe
Implementing an Anonymous FilterTo use the
Download the Turnpike Test AppTurnpike Demo Application: URX ShopTo demonstrate a working example of URX Turnpike we’ve built a sample ecommerce app called URX Shop. You can download the complete, which you can download here, or download a clean branch that starts off at the “Installation” stage of these docs. Either way, you’ll need to sign up for and install Parse in order to test URX Shop. This application is a simple ecommerce app, which lists URX clothing items and has a mock shopping cart page. It uses Parse, a mobile and web backend and hosting framework, to store serve URX Shop product data to the iOS and web app at the same time. With both the iOS and web app implemented, you will be able to click a link from the website on your mobile browser and see Turnpike open a specific page in the URX Shop mobile app on your iPhone. This is the same application used in the docs you are currently reading. Please post questions, report bugs, or recommend changes to our documentation on our Google Group, here. Thanks! The URX Team |
|