DeepLinkSDK 0.2.7

DeepLinkSDK 0.2.7

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release May 2015

Maintained by Wes Smith, Chris Maddern.



DeepLink SDK

Overview

The Button DeepLink SDK is a splendid route-matching, block-based way to handle your deep links. Rather than decide how to format your URLs, parse them, pass data, and navigate to specific content or perform actions, this library and a few lines of code will get you on your way.

Full Documentation

Check it out

Try the DeepLinkSDK sample project by running the following command:

pod try "DeepLinkSDK"

Installation

DeepLinkSDK is available through CocoaPods. To install the library, simply add the following line to your Podfile:

pod "DeepLinkSDK"

Usage

Add deep link support to your app in 5 minutes or less following these simple steps.

Note: As of 0.2.0, in all registered routes, paths are considered to begin at the first forward slash. A route component before the first forward slash will be considered the host.



1. Make sure you have a URL scheme registered for your app in your Info.plist


2. Create an instance of DPLDeepLinkRouter in your app delegate

- (BOOL)application:(UIApplication *)application
        didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  self.router = [[DPLDeepLinkRouter alloc] init];

  return YES;
}


3. Register a route handler

self.router[@"/log/:message"] = ^(DPLDeepLink *link) {
  NSLog(@"%@", link.routeParameters[@"message"]);
};


4. Pass incoming URLs to the router

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

  [self.router handleURL:url withCompletion:NULL];

  return YES;
}

Learn more about the DeepLinkSDK by reading our Integration Guide.

Route Registration Examples

URLs coming into your app will be in a similar format to the following: <scheme>://<host>/<path-component>/<path-component>

When registering routes, it's important to note that the first forward slash in your registered route determines the start of the path to be matched. A route component before the first forward slash will be considered to be the host.

Say you have an incoming URL of twitter://timeline

// Matches the URL.
router[@"timeline"] = ^{ … }

// Does not match the URL.
router[@"/timeline"] = ^{ … }

In another example, a URL of twitter://dpl.com/timeline

// Matches the URL.
router[@"/timeline"] = ^{ … }

// Does not match the URL.
router[@"timeline"] = ^{ … }

You can also be scheme specific. If you support multiple URL schemes in your app, you can register routes specific to those schemes as follows:

An incoming URL of scheme-one://timeline

// Matches the URL.
router[@"scheme-one://timeline"] = ^{ … }

// Does not match the URL.
router[@"scheme-two://timeline"] = ^{ … }

AppLinks Support

Does you app support AppLinks? You can easily handle incoming AppLinks by importing the AppLinks category DPLDeepLink+AppLinks. The AppLinks category provides convenience accessors to all AppLinks 1.0 properties.

router[@"/timeline"] = ^(DPLDeepLink *link) {
  NSURL *referrerURL  = link.referralURL;
  NSString *someValue = link.extras[@"some-key"];
}

Running the Demo

To run the example project, run pod try DeepLinkSDK in your terminal. You can also clone the repo, and run pod install from the project root. If you don't have CocoaPods, begin by follow this guide.

There are two demo apps, SenderDemo, and ReceiverDemo. ReceiverDemo has some registered routes that will handle specific deep links. SenderDemo has a couple actions that will deep link out to ReceiverDemo for fulfillment.

Run theSenderDemo build scheme first, then stop the simulator and switch the build scheme to ReceiverDemo and run again. Now you can switch back to the SenderDemo app in the simulator and tap on one of the actions.

Creating Deep Links

You can also create deep links with DPLMutableDeepLink. Between two DeepLinkKit integrated apps, you can pass complex objects via deep link from one app to another app and easily get that object back on the other end.

In the first app:

NSMutableDeepLink *link = [[NSMutableDeepLink alloc] initWithString:@"app-two://categories"];
link[@"brew-types"] = @[@"Ale", @"Lager", @"Stout", @"Wheat"]
link[@"beers"] = @{
  @"ales": @[
    @{
        @"name": @"Southern Tier Pumking Ale",
        @"price": @799
    },
    @{
        @"name": @"Sierra Nevada Celebration Ale",
        @"price": @799
    }
  ],
  @"lagers": @[
     ...
  ],
  ...
}

[[UIApplication sharedApplication] openURL:link.URL];

In the second app:

router[@"categories"] = ^(DPLDeepLink *link) {
  NSArray *brewTypes  = link[@"brew-types"];
  NSDictionary *beers = link[@"beers"];
}

Authors

Wes Smith
Chris Maddern

License

DeepLinkSDK is available under the MIT license. See the LICENSE file for more info.

Contributing

We'd love to see your ideas for improving this library. The best way to contribute is by submitting a pull request. We'll do our best to respond to you as soon as possible. You can also submit a new Github issue if you find bugs or have questions. :octocat:

Please make sure to follow our general coding style and add test coverage for new features!