Auto Load Banner

Integrate auto-load banners

Autoload banner placement is a new type of banner placements that serves as a container for banner ads. It is commonly used as a static, constantly shown, part of the app’s presentation. The ad content of the banner changes over time depending on the Refresh Rate placement setting on Gravite dashboard.

Create Placement

To create an instance of AATAutoLoadBannerPlacement, use the following API:

lazy var placement = AATSDK.createAutoLoadBannerPlacement(name: "<PLACEMENT_NAME>", size: .banner320x50)

You have to specify a placement name and the size argument of the type AATBannerPlacementSize which specifies the size of the ad to be displayed.

Listen to Callbacks (Optional)

Through the use of AATAutoLoadBannerPlacementDelegate, you can listen to the different placement callbacks.

placement.delegate = self

Get the Banner View

The autoload banner placement provides a banner ad view once and will keep responsible for refreshing the displayed ad content over time. So, once you’ve created the placement, get the ad container view via this method func getPlacementView() -> UIView? and display it on the screen. The placement will update the view content every time it has got a new ad.

if let bannerAdView = placement.getPlacementView() {
    view.addSubview(bannerAdView)
    // Change the bannerAdView frame to your desired location on the screen
}

Request Ad

You can load ads for the autoload banner placement automatically.

If you do not set the refresh time interval seconds on the dashboard, AATKit will:

  • Reload every 30 seconds.

  • respect the refresh time interval setting of the Dashboard (which means, you can configure the interval without having to re-publish your app).

Note: please make sure to disable (or not enable) automatic banner refresh at your ad networks of choice. Otherwise, the different auto reloads would interfere with each other.

// reload the banner placement every 30 seconds.
placement.startAutoReload()

The minimum refresh time is 30 seconds.

This needs to stop the auto-reload when it is no longer needed (e.g. if the view controller presenting ads will disappear):

placement.stopAutoReload()

One Placement for Multiple Screens

If the same placement is used on various different pages of the app and you want to load a new ad every time the user navigates to another page, you can achieve that by calling stopAutoReload() in the first controller and then call startAutoReload() in the next controller. This will immediately load and present a banner ad.

placement.stopAutoReload()
// move to next screen
placement.startAutoReload()

Complete Code Example

class ViewController: UIViewController {
    // Create the placement
    lazy var placement = AATSDK.createAutoLoadBannerPlacement(name: "<PLACEMENT_NAME>", size: .banner320x50)
 
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        // [IMPORTANT] Notify AATKit about the currently active view controller
        AATSDK.controllerViewDidAppear(controller: self)
        
        // Set placement delegate to listen to the callbacks
        placement.delegate = self
        
        // Get the banner view
        if let bannerAdView = placement.getPlacementView() {
            view.addSubview(bannerAdView)
            // Change the bannerAdView frame to your desired location on the screen
        }
        
        // reload the banner placement every 30 seconds.
        placement.startAutoReload()
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        // [IMPORTANT] Remove the currently active view controller
        AATSDK.controllerViewWillDisappear()
        // [IMPORTANT] Stop placement auto-reload
        placement?.stopAutoReload()
    }
}

extension ViewController: AATAutoLoadBannerPlacementDelegate {
    func aatHaveAd(placement: AATPlacement) {
        // The placement has loaded a new ad
    }

    func aatNoAd(placement: AATPlacement) {
        // The placement could not load a new ad
    }
    
    func aatPauseForAd(placement: AATPlacement) {
        // The placement has displayed an ad
    }

    func aatResumeAfterAd(placement: AATPlacement) {
        // Back to the app after clicking on the ad
    }
}

Last updated