Alamofire Integration

DataDome SDK Initalization

Start by declaring a DataDomeSDK variable to be used later:

var dataDomeSdk: DataDomeSDK?

Please make sure to init the SDK by providing all the needed information for its proper functioning:

override func viewDidLoad() {

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

DataDome Alamofire Session Adapter / Retrier

Following the SDK initialization, set the Adapter and Retrier of your SessionManager.

If your DataDomeSDK version is 1.6.5 or later, you can add the Adapter and Retrier during Session initialization:

override func viewDidLoad() {

    super.viewDidLoad()
  
    // After sdk initialized
    // Set adapter and retrier on Session Initialization
    let innterceptors = Interceptor(adapter: dataDomeSdk?.alamofireSessionAdapter,
                                  retrier: dataDomeSdk?.alamofireSessionRetrier)
    let session = Session(configuration: YourConfiguration,
                        interceptor: innterceptors)
}

If your DataDomeSDK version is 1.6.4 or earlier, you can add the Adapter and Retrier to your SessionManager:

override func viewDidLoad() {

    super.viewDidLoad()
  
    // If you have DataDomeSDK <= 1.6.4
    // After sdk initialized
    // Set adapter and retrier of your SessionManager
    AlamofireSessionManager.adapter = dataDomeSdk?.alamofireSessionAdapter
    AlamofireSessionManager.retrier = dataDomeSdk?.alamofireSessionRetrier
}

DataDome Alamofire Request

To protect all your requests, you need to add withDatadome(datadomeSdk) in your request building:

func makeRequest(myUrl: URL) {

    AlamofireSessionManager
        .request(YourEndpoint)
        .validate()
        .withDatadome(datadomeSdk)
        .responseJSON { res in
    }
}

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