Banner
Banner ads are classic static banners, usually located at the bottom or top of the screen. Appodeal supports traditional 320x50 banners, 728x90 tablet banners and smart banners that adjust to the size and orientation of the device.
Checking If Ad Is Loaded
You can check if the ad has been loaded before showing it. This method returns a boolean value indicating whether or not the banner has been loaded.
Appodeal.isReadyForShow(with: .bannerTop)
Display Banner At The Bottom Of The Screen
Banner is a singleton now, if you are using bannerTop
or bannerBottom
on different controllers, the SDK will use the same banner instance.
Banner ads are refreshed every 15 seconds automatically by default. To display a banner, you need to call the following code:
Appodeal.showAd(.bannerBottom, rootViewController: self)
Display Banner At The Top Of The Screen
Appodeal.showAd(.bannerTop, rootViewController: self)
Display Banner At The Left Or Right Corner Of The Screen
If your app uses landscape interface orientation you can show Appodeal Banner at the left or right corner. The banner will have the 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)
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!
BannerView
must be on the top of the hierarchy and mustn't be overlapped by other views.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)
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() {}
If automatic caching is ON for the Banner ad type, do not show the banner in the bannerDidLoadAdIsPrecache
callback. The banner will be refreshed automatically after the first show.
Hide
To remove the banner from your view hierarchy:
Appodeal.hideBanner()
Placements
Appodeal SDK allows you to tag each impression with different placement. To be able to use placements, you need to create them in Appodeal Dashboard. Read more about placements.
Appodeal.showAd(.bannerTop, forPlacement: placement, rootViewController: self)
Appodeal.canShow(.bannerTop, forPlacement: placement)
If you have no placements or call Appodeal.show with a placement that does not exist, the impression will be tagged with 'default' placement with corresponding settings applied.
Important!
Placement settings affect ONLY ad presentation, not loading or caching.
Advanced
Advanced BannerView Integration
If 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.
Enable Smart Banners
Smart banners are banner ads which automatically fit the screen/container size. Using them helps to deal with 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
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
Enable Banner Refresh Animation
//for top/bottom banners Appodeal.setBannerAnimationEnabled(true) //for bannerView bannerView.bannerAnimationEnabled = true
Get Predicted eCPM
This method returns the expected eCPM for the cached ad. The amount is calculated based on historical data for the current ad unit.
Appodeal.predictedEcpm(for: .banner)
Check If Banner Is Initialized
Appodeal.isInitialized(for: .banner)
Returns true
if banner was initialized.
Check If Autocache Is Enabled
Appodeal.isAutocacheEnabled(.banner)
Returns true
if autocache is enabled for banner.