Banner ads are classic static banners, which are usually located at the bottom or top of the advertisement. Appodeal supports traditional 320x50 banners, tablet banners 728x90 and smart banners that adjust to the size and orientation of the device.

1. Manual Caching

By default, auto caching is enabled: Appodeal SDK starts to load Banner right away after the initialization method is called. The next banner ad starts to load after the previous one was shown.

To disable automatic caching for banners, use the code below before the SDK initialization:

Appodeal.setAutocache(false, types: .banner)
To cache banner use:
Appodeal.cacheAd(.banner)
Read more on manual caching in our FAQ.

2. Check if banner is loaded

You can check status of loading before showing. This method return  a boolean value indicating whether the banner is loaded.

Appodeal.isReadyForShow(with: .bannerTop)
We recommend you check caching it before trying to show. 

3. Display banner at the bottom of the screen

Banner is a singleton now, if you are using bannerTop or bannerBottom on different controllers then the SDK will use the same banner instance.
Banner ads are refreshed every 15 seconds automatically by default. To display banner, you need to call the following code:

Appodeal.showAd(.bannerBottom, rootViewController: self)

4. Display banner at the top of the screen

Appodeal.showAd(.bannerTop, rootViewController: self)

5. Display banner at the the screen left or right corner

If your app uses landscape interface orientation you can show Appodeal Banner at the left or right corner. The banner will have offset according to the safe area layout guide.

Disable banner smart sizing if you use AppodealShowStyleBannerLeft or AppodealShowStyleBannerRight

// Overrides default rotation angles
// Appodeal.setBannerLeftRotationAngleDegrees(90, rightRotationAngleDegrees: 180)


Appodeal.showAd(.bannerLeft, forPlacement: placement, rootViewController: self)
// Appodeal.showAd(.bannerRight, forPlacement: placement, rootViewController: self)

6. Display banner in programmatically created view

You can also add the Appodeal banner to your view hierarchy manually.

For example:

override func viewWillAppear(_ animated: Bool) {
	super.viewWillAppear(animated)
    if let banner = Appodeal.banner() {
    	self.view.addSubview(banner)
        banner.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 50)
    }
}

Important!

Custom BannerView must be on the top of the hierarchy and mustn't be overlapped by another views.

7. Use banner callbacks

Callbacks are used to track different lifecycle events of an ad, e.g., when a banner has successfully loaded or is about to appear. To get them, you need to set the delegate as follows:

//set delegate
Appodeal.setBannerDelegate(self)
Usually, the class that implements banners is also the delegate class. That’s why the delegate property can be set to self.

Now you can use the following callback methods:

// banner was loaded (precache flag shows if the loaded ad is precache)
func bannerDidLoadAdIsPrecache(_ precache: Bool) {}
// banner was shown
func bannerDidShow() {} 
// banner failed to load
func bannerDidFailToLoadAd() {}
// banner was clicked 
func bannerDidClick() {} 
// banner did expire and could not be shown
func bannerDidExpired() {} 

All callbacks are called on the main thread.

If automatic caching is ON for the Banner ad type, do not show banner in the bannerDidLoadAdIsPrecache callback. The banner will be refreshed automatically after the first show.

8. Hide banner

To remove banner from your view hierarchy:

Appodeal.hideBanner()

9. Banner Placements

Appodeal SDK allows you to tag each impression with different placement. For using placements you need to create placements in Appodeal Dashboard.  Read more  about placements.

Appodeal.showAd(.bannerTop, forPlacement: placement, rootViewController: self)
If the loaded ad can’t be shown for a specific placement, nothing will be shown. If auto caching is enabled, sdk will start to cache another ad, which can affect display rate. To save the loaded ad for future use (for instance, for another placement) check if the ad can be shown before calling show method:


Appodeal.canShow(.bannerTop, forPlacement: placement)
You can configure your impression logic for each placement.

If you have no placements, or call  Appodeal.show  with placement that do not exist, the impression will be tagged with 'default' placement and its settings will be applied.

Important!

Placement settings affect ONLY ad presentation, not loading or caching.

10. Advanced banner integration

Advanced BannerView integration

If the basic integration is not appropriate for you due to the complex views hierarchy of your app, you can use AppodealBannerView UIView subclass to integrate banners.

import UIKit
import Appodeal

class YourViewController : UIViewController, AppodealBannerViewDelegate {

  override func viewDidLoad () {
    super.viewDidLoad()
    // required: init ad banner
    var bannerView: AppodealBannerView!
    bannerView.init(size: bannerSize, rootViewController: self);

    // optional: set delegate
    bannerView.setDelegate(self);

    // required: add banner to superview and call -loadAd to start banner loading
    self.view addSubview(bannerView);
    bannerView.loadAd();
  }

  // optional: implement any of AppodealBannerViewDelegate methods
  func bannerViewDidLoadAd(_ bannerView: APDBannerView, isPrecache precache: Bool) {
     NSLog("bannerView was loaded")       
  }

  func bannerView(_ bannerView: APDBannerView, didFailToLoadAdWithError error: Error) {
     NSLog("bannerView failed to load");        
  }

  func bannerViewDidInteract(_ bannerView: APDBannerView) {
     NSLog("bannerView was clicked")
  }

  func bannerViewDidShow(_ bannerView: APDBannerView) {
     NSLog("bannerView was shown")
  }

  func bannerViewExpired(_ bannerView: APDBannerView) {
     NSLog("bannerView did expire and could not be shown")
  }
}

 11. Enable smart-banners

Smart banners are the banner ads which automatically fit the screen/container size. Using them helps to deal with the increasing fragmentation of the screen sizes on different devices. To enable them, use the following method:

//for top/bottom banners allows banner view to resize automatically to fit device screen
Appodeal.setSmartBannersEnabled(true)
//for banner view allows banner view to resize automatically to fit device screen
bannerView.usesSmartSizing = true

 12. Change banner background

This method allows to create a grey background for banner ads: 

//for top/bottom banners
Appodeal.setBannerBackgroundVisible(true)

//for bannerView
bannerView.backgroundVisible = true

 13. Enable banner refresh animation

//for top/bottom banners
Appodeal.setBannerAnimationEnabled(true)

//for bannerView
bannerView.bannerAnimationEnabled = true

14. Get Predicted eCPM

This method return expected eCPM for cached ad. Amount is calculated based on historical data for the current ad unit.

Appodeal.predictedEcpm(for: .banner)

15. Check if banner was initialized

Appodeal.isInitialized(for: .banner)

Returns true, if banner was initialized.

16. Check if autocache is enabled for banner

Appodeal.isAutocacheEnabled(.banner)

Returns true, if autocache is enabled for banner.