[L3882] Handling Deep Links in the SDK - Adobe-Marketing-Cloud/aml-summit-lab GitHub Wiki
Handling Deep Links in the SDK
Objective
In this lab exercise, you will learn how to track a deep link in the SDK. Additionally, when users of the app click-through the deep link to open the app, they will automatically be navigated to the "Select a destination" page and be presented with a hidden destination to travel to.
Pre-requisites
It will be helpful to have a good basic understanding of how to create a deep link in the Adobe Mobile Services UI. You can learn more about how to do this by completing the Creating Deep Links in Adobe Mobile Services lab exercise.
Implementation steps
Review pre-configured setup for handling custom URLs in your app
- Click on SummitMobileLab project in the Project Navigator.
- Select the TARGET named SummitMobileLab.
- Select the Info tab on the top.
- Expand the section near the bottom called URL Types.
- With this configuration, we have informed the Operating System that we want our app to respond to the custom URL scheme
com.adobe.summitlab. Whenever the OS needs to open a link with our URL scheme, it will ask the user if they want to open our app to handle the link.
Pass the Deep Link to the SDK and enable the secret lounge
- Navigate to AppDelegate.m
-
When our app opens a deep link, we need to pass that link to the SDK. In our implementation, we will also navigate our users directly into the Select a Destination screen and indicate that the user has a "special offer".
In theapplication:openURL:options:method, copy in the following code:if ([[url scheme] isEqualToString:@"com.adobe.summitlab"]) { /* Adobe Analytics * * 1. track the deep link used as an entry point to the app */ [ADBMobile trackAdobeDeepLink:url]; _hasSpecialOffer = YES; [(ProfileViewController *)self.window.rootViewController performSegueWithIdentifier:@"loginToMap" sender:@"deeplink"]; return YES; }
- Navigate to ProfileViewController.m
-
Prior to performing the navigation to the page where the user would normally select their destination, we will detect if our user launched the app from clicking through a deep link. If they did, we will pre-select the Secret Lounge as their destination.
Copy the following code into theprepareForSegue:sender:method:// if this is from our deeplink, set the destination to the secret lounge if ([sender respondsToSelector:@selector(isEqualToString:)] && [sender isEqualToString:@"deeplink"]) { trip.destination = [AppDelegate destinations][@"Secret Lounge"]; }
- Navigate to MapViewController.m
-
If the users has opened the app via a deep link, we should show the hidden area on our map. Add code that checks for a secret offer if the
checkForSecretOffer:method:// only show secret lounge if they opened from a deeplink [_btnSecretLounge setHidden:![AppDelegate hasSpecialOffer]]; [self updateDestinationLabelWithExistingDestination];
- Run the app.
-
Go back to the home screen and open Safari on the Simulator
-
If you completed the Creating Deep Links in Adobe Mobile Services lab exercise, you can paste the resulting URL to trigger the deep link.
If you have not created a deep link in the Mobile Services UI, enter in the following URL and navigate to it:
com.adobe.summitlab://secretOffer
- Depending on which method you used in step 9, you may see an interstitial in the web. If you do, click the button to open the app. You will get a message in Safari asking you if you want to open the page in SummitMobileLab. Hit the Open button.
- Enjoy your complimentary trips to and from the Secret Lounge!
Next steps
Learn how to Customize your Marketing Link interstitial.