SWIFT SDK FAQ

Use the following method with the desired size:

public func setDefaultBannerSize(size: String)

I need to play Audio Ads along with Dialogue Ads. What I need to do?

Just use

prepare(type: .any)

instead of

prepare(type: .voice)

How to handle AdmanStateError state?

In case of an error, you will receive .error in AdmanState. Please find the ways to handle it below:

func admanStateDidChange(sender: Adman) {
        switch (sender.state) {
        case .error:
            do_something()
        default:
            break
        }
}

// to get detailed error info (if needed)
func errorReceived(err: Error) {
        do_something()
}

How to handle ad preloading?

When using the ad preloading, it is necessary to call the method adman.reportAdEvent(eventName: "can_show") at the time of possible launch of advertising, even in cases, when advertising wasn't actually loaded or played.This method provides the measurement of advertising capacity.​

How to create two instances of Adman with different regions?

init() {
        admanEU = Adman(siteId: 777, testMode: false, zoneId: 0, region: .EU, playerId: 0)
        admanEU.delegate = self
        admanUS = Adman(siteId: 778, testMode: false, zoneId: 0, region: .global, playerId: 0)
        admanUS.delegate = self
}

func admanStateDidChange(sender: Adman) {
        case .adNone:
            if sender.currentRegion() == .EU {
                admanUS.prepare()
            }
        default:
            break
        }
}

How to call an ad with specific slot?

In order to specify the slot for an ad, the below method should be called before calling prepare

setAdSlot(slot: slot)

Possible values for slot (AdmanAdSlot):

How to change the look of the DefaultView?

open class AdmanUIBase is responsible for the view of the ads and can be inherited by another class in the application. Any changes of the view can be done in the inherited subclass.

Background color can be changed in the subclass that inherited the AdmanUIBase class in method open func initBaseView()

view.backgroundColor = UIColor.black

Font color of labels can be changed in the subclass of the AdmanUIBase class in method open func initBaseView()

intentLabel.textColor = UIColor.white
remainingTime.textColor = UIColor.white

How to set the size of Ad View?

You can change the banner view bounds from the extension of AdmanUIBase:

let bounds = UIScreen.main.bounds
bannerView.frame = bounds

This parameter must be used with 'prepare' method when you are preloading an ad. Please find some usage examples below:

public func prepare()

public func prepare(format: AdmanFormat)

public func prepare(type: AdmanType)

public func prepare(format: AdmanFormat, type: AdmanType)

public func prepare(maxDuration: Int, adsCount: Int)

public func prepare(format: AdmanFormat, type: AdmanType, maxDuration: Int, adsCount: Int)

For CCPA consent string please use the following before the ad request:

adman.setSiteVariable(key: "us_privacy", value: "PrivacyData")

How to customize the look of the ad view?

After Adman initialization you will need to create AdmanUIBase class.

This class must be initialized before calling adman.prepare()

On the ad playback, the following method should be called:

admanUIBase.show(rootVC: viewController)

In order to customize the look of the view, you will need to inherit the AdmanUIBase class and implement its methods:

import Foundation
import Adman_swift
import UIKit

protocol AdmanUIExtensionDelegate: NSObject {
    func refresh()
}
class AdmanUIExtension: AdmanUIBase {
    
    var delegate: AdmanUIExtensionDelegate?
    var devMode: Bool?

    override init() {
        super.init()
        if UserDefaults.standard.bool(forKey: "debug") == true { devMode = true }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func initBaseView() {
        super.initBaseView()
        rewindView.image = loadImageFrom(base64: REFRESH_BTN_SOURCE)
        for rec in (rewindView.gestureRecognizers ?? [UIGestureRecognizer]()) {
            rewindView.removeGestureRecognizer(rec)
        }
        addSelector(sel: #selector(refreshDelegate(uiGestureRecognizer:)), view: rewindView, target: self)
    }
    
    override func initVoiceView() {
        super.initVoiceView()
        positiveView.image = nil
        negativeView.image = nil
        intentLabel.text = ""
    }
    
    override func show(rootVC: UIViewController) {
        super.show(rootVC: rootVC)
        if devMode ?? false {
            remainingTime.isHidden = true
            view.backgroundColor = nil
        }
    }
    
    override func update(ad: AdmanBannerWrapper) {
        super.update(ad: ad)
        if devMode ?? false { bannerView.image = nil }
    }

    @objc func refreshDelegate(uiGestureRecognizer: UIGestureRecognizer) {
        delegate?.refresh()
    }
    
    @objc override func admanVoiceNotification(notification: NSNotification) {
        super.admanVoiceNotification(notification: notification)
        let dict = notification.userInfo
        guard let message = dict?[NOTIFICATION_ADMAN_VOICE_KEY] as? NotificationAdmanVoice else { return }
        switch message.event {
        case .recognizerStarted: 
            break
        default: break
        }
    }
}

You can find the example in test applications of Adman_swift framework (files: AdmanUIExt.swift and PlayerVC.swift )

How to use variables for targeting in the SDK?

Please use the following method BEFORE requesting an ad:

public func setSiteVariable(key: String, value: String)

Last updated