How To Implement Deep Linking on iOS

Continued from page 1.

Using Button DeepLink SDK

Button’s DeepLink SDK is part of the company's suite of solutions including its Loyalty/Rewards Program API, DeepLink Commerce and CartAdjust, which applies DeepLink and commerce promotions and link them to the app’s cart.

Similar to the other deep-linking solutions we evaluated, Button DeepLink SDK provides a route-handling mechanism that allows for passing and handling of data, then routes (or navigates) to the specific contextual content. However, unlike App Links, DeepLink is iOS-only.

Getting started with Button DeepLink SDK

image

Getting started with this SDK is extremely straightforward, using the popular CocoaPods package-management framework:

pod "DeepLinkSDK"

We will start with The Router, which will be centralized in your application’s AppDelegate file:

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

  self.routerManager = [[**DPLDeepLinkRouter** alloc] init];

  return YES;
}

We need to register Routes, which can be done in the following fashion:

...
self.routerManager[@"/profile/:username"] = ^(DPLDeepLink *link){

ProfileViewController* pvc = [[ProfileViewController alloc] initWithProfileUserName:link.routeParameters[@"username"]
// we then would call the view controller passing after initialising with the link parameters
...

Receiving Deep Links and assigning them to the router is done in a similar way to how we did it with App Links, using the application:openURL:sourceApplication:annotation: method override in AppDelegate. The following handles the url passed in, and assigns it to the routerManager object we declared earlier:

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

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

  return YES;
}

Routes can also be assigned to classes instead of blocks, as follows:

self.routerManager[@"/profile/:profile_id"] = [ProfileRouteHandler class];

If the view controller receives a URL with the path of /profile/1234, the router will then instantiate through the handler subclassing your target view controller, passing in the appropriate information. We will need to conform to the DPLTargetViewControllerProtocol so that we can implement the configureWithDeepLink: method:

- (void)configureWithDeepLink:(DPLDeepLink *)deepLink {

    NSString *profileId = deepLink.routeParameters[@"profile_id"];
    self.profile = [Profile profileWithId: profileId];
}

DeepLink and App Links are very similar in a way, from the elementary route-mapping to supporiting link-handling from external origins, such as web Wages or native apps. This SDK, however, is a substantial subset of App Links, as it does not support navigating backward and is not cross-platform (so you are stuck with iOS).

You also don’t get the smarter logic that allows for things like failing links (such as when the user does not have the app). Not being open-sourced, you also don’t get the large and engaged community that App Links enjoys.

What you do get, however, is an easy to use SDK--much easier to use, certainly, than AppLinks.

Be sure to read the next Mobile article: How to Get Started With Apple's ResearchKit