URLSession Integration

DataDome SDK Initalization

First of all, you need to declare a DataDomeSDK var:

var dataDomeSdk: DataDomeSDK?

After that, proceed with the initialization of the DataDomeSDK:

override func viewDidLoad() {

    super.viewDidLoad()
        
    // Init
    dataDomeSdk = DataDomeSDK(containerView: containerView, key: "Client_Side_Key", appVersion: appVersion, userAgent: useragent)
    // Set the delegate
    dataDomeSdk?.delegate = self
}

DataDome URLSession Delegate

Following SDK initialization, you need to set the UrlSession with DataDome UrlSessionDelegate:

override func viewDidLoad() {

    super.viewDidLoad()
  
    // After sdk initialized
    // Set the UrlSession with DataDome UrlSessionDelegate
    urlSession = URLSession(configuration: URLSessionConfiguration.default, delegate: dataDomeSdk, delegateQueue: OperationQueue.main)

}

func makeRequest(myUrl: URL) {
    let request = URLRequest(url: myUrl)
    let task = self.urlSession?.dataTask(with: request, ddSdk: self.dataDomeSdk, completionHandler: { data, response, error in 
    })

    task?.resume()
}

DataDome SDK Listener

The DataDome Listener is optional and provides you with another way to get more information concerning request handling by the SDK with the Captcha lifecycle.

Below is the list of all the listeners provided by the DataDome SDK:

class ViewController: UIViewController, DataDomeSDKDelegate {

    override func viewDidLoad() {

        super.viewDidLoad()
        // Init of SDK and view here
        // And set the delegate
        dataDomeSDK.delegate = self
    }


    // MARK : - DataDomeSDKDelegate methods

    func captcha(_ instance: DataDomeSDK, willAppear webView: UIView?) {
        // Called when captcha will appear
    }

    func captcha(_ instance: DataDomeSDK, didAppear webView: UIView?) {
        // Called when captcha did appear
    }

    func captcha(_ instance: DataDomeSDK, willDisappear webView: UIView?) {
        // Called when captcha will disappear
    }

    func captcha(_ instance: DataDomeSDK, didDisappear webView: UIView?) {
        // Called when user successfully pass the captcha
        // you can now re-send your request and get your data
    }

    func datadomeRespond(_ responseCode: Int, withData data: Any?) {
        // request was not blocked by DataDome
        // all your response values are in data
    }
}