Top
How to set up a Deep link in iOS?
  • 25 Jan 2024
  • 3 Minutes To Read
  • Dark
    Light
  • PDF

How to set up a Deep link in iOS?

  • Dark
    Light
  • PDF

Article Summary

Deep link enables you to link directly to the content present in your app itself. You can embed a deep link in Whatfix Mobile projects like Walkthrough, Pop-ups, etc, and inside project elements like buttons, texts, etc. Once the element is clicked, the added deep link page opens.

Set up Deep link

Add the URL Scheme to your project:

  1. Open your project.xcodeproj. Under targets, select your app and go to the info section.
  2. Scroll down to see the URL Types and click + to add a new URL Type.
    url_types
  3. Add your app's name or any desired name in the URL Schemes field. This is your schemeName.
  4. Add your app's bundle identifier or any unique identifier in the identifier field.
your title goes here

This is not a mandatory step.

Below iOS 13

  1. Add the open URL method in the AppDelegate.swift file.
  2. In the Whatfix Mobile Dashboard, make sure to use the format schemeName://pageName.
    Example: demoApp://profile
  3. If the schemeName in your project URL Schemes matches with the Dashboard schemeName, the user is redirected to the following method.
    If you have a profile page and you want to add deep link capability to that, use the following code snippet,
// AppDelegate.swift

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : An] = [:]) -> Bool {

guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true),
      let host = components.host else {
            return false
        }
     
// Extract host. Host is your pageName. Based on the host name, go to the 
// desired view or view controller like below or you can do in your way based 
// on your app's architecture.

guard let deeplink = DeepLink(rawValue: host) else {
            return
        }
        
        mainController?.handleDeeplink(deeplink)
        
        return true
 }

// global type
enum DeepLink: String {
    case home
    case profile
}

// MainController.swift

func handleDeeplink(_ deeplink: DeepLink) {
        switch deeplink {
        case .home:
            let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "HomeViewController") as? HomeViewController
            self.navigationController?.pushViewController(vc!, animated: true)
        case .profile:
            let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "ProfileViewController") as? ProfileViewController
            self.navigationController?.pushViewController(vc!, animated: true)
        }
    }

iOS 13 and above

  1. Add the open URLContexts method in the SceneDelegate.swift file
  2. In the Whatfix Mobile Dashboard, make sure to use the format schemeName://pageName.
    Ex: demoApp://profile
  3. If the schemeName in your project URL Schemes matches with the Dashboard schemeName, the user is redirected to the following method.
    If you have a profile page and you want to add deep link capability to that, use the following code snippet,
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        
guard let url = URLContexts.first?.url else { return }
        
guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true), 
      let host = components.host else {
          return
      }

// Extract host. Host is your pageName. Based on the host name, go to the 
// desired view or view controller like below or you can do in your way based 
// on your app's architecture.
        
       guard let deeplink = DeepLink(rawValue: host) else {
            return
        }
        
        mainController?.handleDeeplink(deeplink)
 }

// global type
enum DeepLink: String {
    case home
    case profile
}

// MainController.swift

func handleDeeplink(_ deeplink: DeepLink) {
        switch deeplink {
        case .home:
            let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "HomeViewController") as? HomeViewController
            self.navigationController?.pushViewController(vc!, animated: true)
        case .profile:
            let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "ProfileViewController") as? ProfileViewController
            self.navigationController?.pushViewController(vc!, animated: true)
        }
    }

Deep links in Flow Menu

When configuring a Flow Menu (i.e. Walkthrough Checklist/Walkthrough Menu), for a particular menu, item you can add a deep link. It is better if a particular menu item of the Flow Menu is configured on a different page (not the same as the start screen). With the help of deep link, Whatfix Mobile can go to the required page.

Consider that you want to add a deep link in a Walkthrough Checklist,
Flow_menu

The menu item Profile is configured on a different page (not the same as the start screen). To go to the required page, you can add the deep link using the following steps,

  1. Click Profile.
  2. On the right, under the DEEPLINK section, add your configured deep-link URL.

The following image shows adding a deep link in the Dashboard with the format, schemeName://pageName,
Flow_menu_demo_url


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.