Separate Loading and Rendering of Banner Ads

The RTBBannerAdProviderarrow-up-right offers the app full control over the lifecycle of individual banner ad impressions. It allows the app to load a banner ad independently, with the option to render it at a later time. By loading an ad with a specific configuration, the app receives notifications about the result of that load request through the RTBBannerAdLoadDelegatearrow-up-right. As a result, the RTBBannerAdProvider is used differently from the RTBBannerView.

Request Ad

To load a banner ad, you will need to pass an instance of RTBBannerRequestConfigurationarrow-up-right with placementID and the bundleId. Please contact our supportenvelope to get the needed IDs.

let configuration = RTBBannerRequestConfiguration(placementId: <PLACEMENT_ID>, iTunesAppId: <ITUNES_APP_ID>)
configuration.sellerId = "<SELLERID>" // Optional
configuration.bidFloor = <BID_FLOOR>  // Optional (in USD)
RTBBannerAdProvider.load(configuration: configuration, size: .banner320x50, userAgent: "<USER_AGENT>", loadDelegate: self)

You will be notified about the loading success or failure through the RTBBannerAdLoadDelegatearrow-up-right instance passed as loadDelegate. If the ad loads successfully, you will obtain RTBBannerBid instance that can later be used to obtain the banner view.

Optional - set user targeting

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

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

Get Loaded Banner View

Once the banner is loaded and the method bannerAdDidReceiveAd(bannerBid: RTBBannerBid) is called, you can get the loaded banner view by calling the RTBBannerAdProvider.getBannerView(bannerBid: bannerBid, delegate: self) method passing the received RTBBannerBidarrow-up-right instance. You can also pass optional RTBBannerAdInteractionDelegatearrow-up-right that will be notified about banner events like clicks.

func bannerAdDidReceiveAd(bannerBid: RTBSDK.RTBBannerBid) {
    DispatchQueue.main.async {
        guard let bannerView = RTBBannerAdProvider.getBannerView(bannerBid: bannerBid, delegate: self) else {
            return
        }
        let price = bannerBid.priceCPM // in USD
        let bidder = bannerBid.bidder
        // Adjust and display the banner view
    }
}

The currency of bidFloor and priceCPM parameters is USD.

Complete Code Example

Last updated