Hybrid App Setup - iOS SDK (v4)

Note

Before proceeding with the hybrid app setup, install the iOS SDK and Web SDK.

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_TOKENis the Web SDK token. You can find it on the [Settings]>[Tokens] page in the Airbridge dashboard.

123456789101112131415161718192021222324252627
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")!))
    }
}

Add the Airbridge.click function 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.

123456789101112131415161718192021222324
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)
}

Attention

Was this page helpful?

Have any questions or suggestions?