(EN) iOS_Swift Banner - adxcorp/ADXLibrary_Integration GitHub Wiki

Banner Integration

1) Implementing Banner Ad

MyViewController.swift

import MoPub

class ViewController: UIViewController {
    fileprivate var mopubAdView : MPAdView!

    override func viewDidLoad() {
        super.viewDidLoad()
        setupADBanner()
    }
}

extension ViewController : MPAdViewDelegate {
    //Banner
    func setupADBanner() {
        mopubAdView = MPAdView(adUnitId: "<YOUR_ADUNIT_ID_HERE>", size: MOPUB_BANNER_SIZE)
        mopubAdView.delegate = self
        var frame = mopubAdView.frame
        let size = mopubAdView.adContentViewSize()
            
        frame.origin = CGPoint(x: (UIScreen.main.bounds.width - size.width)/2,
                               y: UIScreen.main.bounds.height - size.height - UIApplication.shared.statusBarFrame.height)
        mopubAdView.frame = frame
        mopubAdView.loadAd()
            
    }

    // MARK: - MPAdViewDelegate
    func viewControllerForPresentingModalView() -> UIViewController! {
        return self
    }
        
    func adViewDidLoadAd(_ view: MPAdView!) {
        print(view.description)
    }
}

2) Delegate Method

MPAdViewDelegate provides various callbacks, such as when ad has been successfully loaded or when modal view is presented or dismissed. Please refer to callback methods that are found by looking at MPAdViewDelegate protocol in MPAdview.h and use them appropriately to your needs.