Banner

Banner ads occupy a spot within an app's layout, either at the top or bottom of the device screen. They stay on screen while users are interacting with the app, and can refresh automatically after a certain period of time.

Prerequisites

Always test with test ads

When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to the suspension of your account. The easiest way to load test ads is to use our dedicated test ad unit ID for app banner ads:

63a573861ac5f

It's been specially configured to return test ads for every request, and you're free to use it in your own apps while coding, testing, and debugging. Just make sure you replace it with your own ad unit ID before publishing your app.

Create a Adx3BannerAdView

Banner ads are displayed in Adx3BannerAdView objects, so the first step toward integrating banner ads is to include an Adx3BannerAdView in your view hierarchy. This is typically done either with the interface builder or programmatically.

Interface Builder

An Adx3BannerAdView can be added to a storyboard or XIB file like any typical view. When using this method, be sure to add width and height constraints to match the ad size you'd like to display. For example, when displaying a banner (250x150), use a width constraint of 250 points, and a height constraint of 150 points.

Programmatically

An Adx3BannerAdView can also be instantiated directly. Here's an example of how to create an Adx3BannerAdView, aligned to the bottom center of the safe area of the screen, with a banner size of 250x150:

class ViewController: UIViewController {
    
    var bannerView : Adx3BannerAdView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.addBannerView()
        // Do any additional setup after loading the view.
    }
    
    func addBannerView() {
        bannerView = Adx3BannerAdView.init(adSize: CGSize(width: 250, height: 150), delegate: self)
        bannerView!.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(bannerView)
        view.addConstraint(NSLayoutConstraint.init(item: bannerView!, attribute: .bottom, relatedBy: .equal, toItem: bottomLayoutGuide, attribute: .bottom, multiplier: 1.0, constant: 0.0))
        view.addConstraint(NSLayoutConstraint.init(item: bannerView!, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1.0, constant: 0.0))
    }

}

Load an ad

Once the Adx3BannerAdView is in place, it's time to load an ad. This is done by calling loadRequestWithPlacementID:userId: delegate on an Adx3BannerAdView object:

 //userId Optional
 self.bannerView.loadRequest(withPlacementID: "Your Placement ID", userId: "", delegate: self)

Ad events

Through the use of Adx3BannerDelegate, you can listen for lifecycle events, such as when an ad is clicked.

func bannerDidClick(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
    print("----banner did click----")
}

Last updated