Hybrid App Setup - iOS SDK (v4)

Note

Before proceeding with the hybrid app settings, 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.

Manage 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 WebView.

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 WebViews. Webviews do not inherently support deep links; therefore, the Airbridge.click function must be used to configure the SDK to handle the deep link within the tracking link.

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

If the input address is not a tracking link, 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?