# Deep Link Native App

## Setting up for iOS

### 1. Adding a URL scheme

Open up **your project** and go to **Targets** > **Info** > **URL Types** and add the following:

<figure><img src="/files/jmWPNbHSOvEv5hlIRQdD" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Change **`com.discoveryloft.pavejs`** to **your project's identifier**
{% endhint %}

### 2. Define your deep links

We are going to support two deep links into the app:

* `pave://home`
* `pave://detail`

And we will represent the `host` part of the URL in an `enum`.

**DeepLink.swift**

```swift
import Foundation

enum DeepLink: String {
    case home
    case detail
}
```

### 3. Handle URLs

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**

```swift
 func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {  
        // Process the URL.
        guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true),
              let host = components.host else {
            print("Invalid URL")
            return false
        }
                
        print("components: \(components)")
        
        // Create the deep link
        guard let deeplink = DeepLink(rawValue: host) else {
            print("Deeplink not found: \(host)")
            return false
        }

        // Hand off to mainViewController
        mainViewController.handleDeepLink(deeplink)
        
        return true
    }
```

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**

```swift
// MARK: Deep Link

extension MainViewController {
    func handleDeepLink(_ deepLink: DeepLink) {
        switch deepLink {
            case .home:
                // handle show your app's home screen here
            case .detail:
                // handle show your app's detail screen here
            default:
                // 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`).

<div align="center"><figure><img src="/files/tcxY8MbtZZTUuRKvv6bl" alt=""><figcaption></figcaption></figure></div>

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 <a href="#adding-filters" id="adding-filters"></a>

To create a link to your app content, add an intent filter that contains these elements and attribute values in your manifest:

```markup
 <application
        ...>

        <activity
            android:name=".MainActivity"
            android:label="MainActivity" >
            
             <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            
            <intent-filter android:label="PAVE Filter">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <!-- Accepts URIs that begin with "pave://...” -->
                <data android:scheme="pave" />

            </intent-filter>
        </activity>

   </application>
```

[According to Google](https://developer.android.com/training/app-links/index.html#android-app-links), 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 <a href="#handling-intents" id="handling-intents"></a>

Here’s a snippet that shows how to retrieve data from an **`Intent`**:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.main)

    val appLinkAction: String? = intent?.action
    val appLinkData: Uri? = intent?.data
    
    if (Intent.ACTION_VIEW == appLinkAction && appLinkData != null) {
      val sessionId = appLinkData.getQueryParameter("sessionId")
      if (sessionId.isNullOrBlank().not()) {
        // handle the PAVE's Session ID here
      }
      
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.paveapi.com/integrations/developer-docs/deep-linking/deep-link-native-app.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
