> ## Documentation Index
> Fetch the complete documentation index at: https://help.airbridge.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Hybrid App Setup - iOS SDK

<Info>
  **Note**

  Before proceeding with the hybrid app setup, install the [iOS SDK](/en/developers/ios-sdk-v4) and [Web SDK](/en/developers/web-sdk).
</Info>

You can configure the iOS SDK to handle Airbridge-related tasks occurring within the in-app website of a hybrid app without modifying the website's code.

## Handle Web SDK Commands with the iOS SDK

The iOS SDK can handle the commands related to event transmission, device settings, and user settings carried out by the Web SDK. Configure the `Airbridge.setWebInterface` function before displaying the website on the web view.

`YOUR_WEB_TOKEN`is the [Web SDK token](/en/guides/tokens#web-sdk-token). You can find it on the **\[Settings]>\[Tokens]** page in the Airbridge dashboard.

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  import UIKit
  import WebKit
  import Airbridge

  class ViewController: UIViewController, WKNavigationDelegate {
      let webView = {
          let configuration = WKWebViewConfiguration()
          let controller = WKUserContentController()
          Airbridge.setWebInterface(
              controller: controller,
              webToken: "YOUR_WEB_SDK_TOKEN"
          )
          
          configuration.userContentController = controller
          
          return WKWebView(frame: .null, configuration: configuration)
      }()

      override func viewDidLoad() {
          super.viewDidLoad()

          webView.navigationDelegate = self
          self.view = webView

          webView.load(URLRequest(url: URL(string: "YOUR_WEBSITE_URL")!))
      }
  }
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  #import <UIKit/UIKit.h>

  @interface ViewController : UIViewController

  @end
  ...
  #import "ViewController.h"

  #import <WebKit/WebKit.h>
  #import <Airbridge/Airbridge.h>

  @interface ViewController () <WKNavigationDelegate>

  @end

  @implementation ViewController {
      WKWebView* webView;
  }

  - (instancetype)init
  {
      self = [super init];
      if (self) {
          WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
          WKUserContentController* controller = [[WKUserContentController alloc] init];
          [Airbridge setWebInterfaceWithController:controller webToken:@"YOUR_WEB_SDK_TOKEN"];

          configuration.userContentController = controller;
          
          webView = [[WKWebView alloc] initWithFrame:CGRectNull configuration:configuration];
      }
      return self;
  }

  - (void)viewDidLoad {
      [super viewDidLoad];
      webView.navigationDelegate = self;
      self.view = webView;
      [webView loadRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"YOUR_WEBSITE_URL"]]];
  }

  @end
  ```
</CodeGroup>

## Enable Deep Links in Web View

Add the [Airbridge.click function](/en/developers/ios-sdk-v4#when-the-user-clicks-a-tracking-link-within-the-app) to enable deep links in the web view. Therefore, the `Airbridge.click` function must be configured so that the SDK can handle the deep link embedded in the tracking link.

The `Airbridge.click` function returns `true` when the input address is a tracking link. When the app is launched through that address, the `onSuccess` function is called. If there is no internet connection or a different app is launched, the `onFailure` function is called.

When the input address is not a tracking link, the `Airbridge.click` function returns `false` , and no further action is executed.

Implementing `webView(_,decidePolicyFor:,decisionHandler:)` in `WKWebView` allows you to determine whether to continue or cancel loading a specific URL after it is detected.

<CodeGroup>
  ```swift Swift lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  func webView(
      _ webView: WKWebView,
      decidePolicyFor navigationAction: WKNavigationAction,
      decisionHandler: @escaping (WKNavigationActionPolicy
  ) -> Void) {
      if let url = navigationAction.request.url {
          let isHandled = Airbridge.click(trackingLink: url) {
              // when url is tracking link and succeed
              // do nothing
          } onFailure: { error in
              // when url is tracking link and failed
              // example: url is another app's tracking link, internet is not connected
              webView.load(URLRequest(url: url))
          }
          if isHandled {
              // when url is tracking link
              decisionHandler(.cancel)
              return
          }
      }
      
      // when url is not tracking link
      decisionHandler(.allow)
  }
  ```

  ```objective-c Objective-C lines theme={"theme":{"light":"github-dark-dimmed","dark":"github-dark-dimmed"}}
  - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
      NSURL* url = navigationAction.request.URL;
      if (url != nil) {
          BOOL isHandled = [Airbridge clickWithTrackingLink:url onSuccess:^{
              // when url is tracking link and succeed
              // do nothing
          } onFailure:^(NSError* error) {
              // when url is tracking link and failed
              // example: url is another app's tracking link, internet is not connected
              [webView loadRequest:[[NSURLRequest alloc] initWithURL:url]];
          }];
          if (isHandled) {
              // when url is tracking link
              decisionHandler(WKNavigationActionPolicyCancel);
              return;
          }
      }
      // when url is not tracking link
      decisionHandler(WKNavigationActionPolicyAllow);
  }
  ```
</CodeGroup>

## Attention

<Accordion title="In-app web view event collection">
  Note that with the hybrid app setup, events that occur in the in-app web view must be collected through the Web SDK only. If collected through the App SDK as well, event duplication will occur. If your in-app web view uses a live mobile website, utilize only the Web SDK for event collection.
</Accordion>

<link rel="alternate" hrefLang="en" href="https://help.airbridge.io/en/developers/hybrid-app-settings-ios-sdk-v4" />

<link rel="alternate" hrefLang="ko" href="https://help.airbridge.io/ko/developers/hybrid-app-settings-ios-sdk-v4" />
