iOS 배너 광고

배너 광고 노출하기

광고 크기를 적용한 광고 유닛 ID로 AdropBanner 를 초기화하고, 광고를 로드하세요.

class ViewController: UIViewController {
    @IBOutlet weak var adContainer: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // 추가 설정은 먼저 view를 로드한 후 진행하세요.
        
        let bannerView = AdropBanner(unitId: "ADROP_PUBLIC_TEST_UNIT_ID")
        bannerView.delegate = self
        bannerView.load()
        adContainer.addSubview(bannerView)
        bannerView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        bannerView.translatesAutoresizingMaskIntoConstraints = false
        bannerView.frame = adContainer.bounds
    }
}

extension ViewController: AdropBannerDelegate {
    func onAdReceived(_ banner: AdropAds.AdropBanner) {
        print("onAdReceived")
    }
    
    func onAdClicked(_ banner: AdropAds.AdropBanner) {
        print("onAdClickced")
    }
    
    func onAdFailedToReceive(_ banner: AdropAds.AdropBanner, _ error: AdropAds.AdropErrorCode) {
        print("onAdFailedToReceive \(AdropErrorCodeToString(code: error))")
    }
}

Last updated