To handle the URL we need to go into our AppDelegate.swift and parse the incoming request, and convert it into a DeepLink that we can hand off to our MainViewController for processing.
AppDelegate.swift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// Process the URL.guardlet components =NSURLComponents(url: url, resolvingAgainstBaseURL:true),let host = components.host else {print("Invalid URL")returnfalse }print("components: \(components)")// Create the deep linkguardlet deeplink =DeepLink(rawValue: host)else {print("Deeplink not found: \(host)")returnfalse }// Hand off to mainViewController mainViewController.handleDeepLink(deeplink)returntrue }
Once in the MainViewController with the deeplink we can do whatever we want. Here we just manually navigate to the view controller in the tab bar we want to present.
MainViewController.swift
// MARK: Deep LinkextensionMainViewController {funchandleDeepLink(_deepLink: DeepLink) {switch deepLink {case .home:// handle show your app's home screen herecase .detail:// handle show your app's detail screen heredefault:// handle the PAVE's Session ID here } }}
4. Test
You can try deeplinking into your app by firing up Safari in your simulator and enter URL in there (i.e. pave://home).
Or an even better way is to execute deeplinks from the command line while your simulator is running with this command here:
xcrun simctl openurl booted pave://home
Setting up for Android
1. Add intent filters for incoming links
To create a link to your app content, add an intent filter that contains these elements and attribute values in your manifest:
According to Google, the autoVerify attribute “allows your app to designate itself as the default handler of a given type of link. So when the user clicks on an Android App Link, your app opens immediately if it's installed — the disambiguation dialog doesn't appear.”
2. Read data from incoming intents
Here’s a snippet that shows how to retrieve data from an Intent: