RTBSDK iOS Integration
Release Notes
  • Start
    • Setup
      • Cocoapods
      • Swift Package Manager
      • Configure RTBSDK
    • Consent
  • Formats
    • Banners
    • Fullscreen (Interstitial)
    • Native Ads
    • Advanced
      • Separate Loading and Rendering of Banner Ads
  • Other
    • AdMob Custom Events
    • AppLovin Custom Adapter
    • Reference
      • Classes
        • RTBSDKManager
        • RTBBannerView
        • RTBBannerAdProvider
        • RTBBannerBid
        • RTBBannerRequestConfiguration
        • RTBBannerSize
        • RTBFullscreenAd
        • RTBFullscreenRequestConfiguration
        • RTBNativeAdLoader
        • RTBNativeAd
        • RTBNativeAdRequestConfiguration
        • RTBUserTargeting
        • RTBBidInfo
      • Protocols
        • RTBBannerViewDelegate
        • RTBBannerAdLoadDelegate
        • RTBBannerAdInteractionDelegate
        • RTBFullscreenDelegate
        • RTBNativeAdLoaderDelegate
        • RTBNativeAdInteractionDelegate
      • Enumerations
        • RTBLogLevel
        • RTBGender
  • Sample App
Powered by GitBook
On this page
  • Create an RTBBannerView Instance
  • Listen to Callbacks
  • Request Ad
  • Optional - set user targeting
  • Complete Code Example
  1. Formats

Banners

Last updated 2 months ago

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 while initialising the RTBBannerView. It will be used later while loading a new banner ad.

Listen to Callbacks

Through the use of , you can listen to the different callbacks. Of course, your class must conform to its delegate methods (see the ).

bannerAdView.delegate = self

Request Ad

To load a banner ad, you will need to pass an instance of with placementIDand iTunesAppId. Please contact our for getting the needed IDs.

let configuration = RTBBannerRequestConfiguration(placementId: <PLACEMENT_ID>, iTunesAppId: <ITUNES_APP_ID>)
configuration.sellerId = "<SELLERID>" // Optional
configuration.bidFloor = <BID_FLOOR>  // Optional
bannerView.load(configuration: configuration)

You will be notified about the loading success/failure through the

The currency of bidFloor and priceCPM parameters is USD.

Optional - set user targeting

let configuration = RTBBannerRequestConfiguration(placementId: <PLACEMENT_ID>, iTunesAppId: <ITUNES_APP_ID>)
configuration.userTargeting = .init(userId: "<USER_ID>", gender: .male, yearOfBirth: 1999, keywords: ["keyword1", "keyword2"])
// yearOfBirth must be a 4-digit number, otherwise, it will be ignored

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
    }
}

You can pass user targeting data to each request, allowing ads to be more relevant to your audience. Each field in is optional.

RTBUserTargeting
banner size
RTBBannerViewDelegate
RTBBannerRequestConfiguration
support
RTBBannerViewDelegate
complete example below