Moya Integration

DataDome SDK Initalization

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

var dataDomeSdk: DataDomeSDK?

After that, the next step is to initialize 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 Moya 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 the session initialization:

override func viewDidLoad() {

    super.viewDidLoad()
  
    // If you have DataDomeSDK >= 1.6.5
    // After sdk initialized
    // Set adapter and retrier on Session Initialization
    let ddInterceptors = Interceptor(adapter: dataDomeSdk?.alamofireSessionAdapter,
                                 retrier: dataDomeSdk?.alamofireSessionRetrier)
    let session = Session(configuration: YourConfiguration,
                        interceptor: ddInterceptors)
}

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
    MoyaSessionManager.adapter = dataDomeSdk?.alamofireSessionAdapter
    MoyaSessionManager.retrier = dataDomeSdk?.alamofireSessionRetrier
}

DataDome Moya Plugin

To protect all your requests, you need to add DataDomePlugin(with: dataDomeSdk) in your Moya providers plugins:

func makeRequest() {

     let provider = MoyaProvider<YourService>(
                             endpointClosure: endPointClosure(), 
                             manager: YourSessionManager, 
                             plugins: [
                                 DataDomePlugin(with: dataDomeSdk)
                             ])
}

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