Banner ads are displayed in RTBBannerView instances, so the first step towards integrating banner ads is to create an instance of RTBBannerView and add it to your view hierarchy.
Create an RTBBannerView Instance
let bannerAdView = RTBBannerView(size: .banner320x50)
You have to specify the banner size while initialising the RTBBannerView. It will be used later while loading a new banner ad.
Listen to Callbacks
Through the use of RTBBannerViewDelegate, you can listen to the different callbacks. Of course, your class must conform to its delegate methods (see the complete example below).
bannerAdView.delegate = self
Request Ad
To load a banner ad, you will need to pass an instance of RTBBannerRequestConfiguration with placementIDand iTunesAppId. Please contact our support for getting the needed IDs.
You will be notified about the loading success/failure through the RTBBannerViewDelegate
The currency of bidFloor and priceCPM parameters is USD.
Complete Code Example
import RTBSDK
class ViewController: UIViewController {
let bannerAdView = RTBBannerView(size: <RTBBannerSize>)
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// [Important] add the banner view to your view hierarchy
self.view.addSubview(bannerAdView)
// [Important] Set the banner ad delegate to listen to the callbacks
bannerAdView.delegate = self
// [Important] Add bannerView to your view hierarchy based on your screen layout
...
// Prepare request configurations
let configuration = RTBBannerRequestConfiguration(placementId: <PLACEMENT_ID>, iTunesAppId: <ITUNES_APP_ID>)
configuration.sellerId = "<SELLERID>" // Optional
configuration.bidFloor = <BID_FLOOR> // Optional
// Request a banner ad
bannerAdView.load(configuration: configuration)
}
}
extension ViewController: RTBBannerViewDelegate {
func bannerViewDidReceiveAd(_ bannerView: RTBBannerView, bidInfo: RTBBidInfo, networkName: String) {
// A banner ad has been loaded and displayed
}
func bannerView(_ bannerView: RTBBannerView, didFailToReceiveAd error: String, networkName: String) {
// Failed to load a banner ad
}
func bannerViewDidRecordClick(_ bannerView: RTBBannerView, networkName: String) {
// The banner received a click
}
func bannerViewDidPauseForAd(_ bannerView: RTBBannerView, networkName: String) {
// The app paused after the use clicked on the ad and opened Safari app
}
func bannerViewDidResumeAfterAd(_ bannerView: RTBBannerView, networkName: String) {
// The app resumed after returning from Safari as a result of user click
}
}