Skip to main content

Overview

Banner ads are rectangular ads displayed in a portion of the screen. They can be used in both UIKit and SwiftUI.

Key Features

  • Can be fixed at the top, bottom, or middle of the screen
  • Supports both image and video ads
  • Supports both UIKit and SwiftUI
  • Ad event handling through delegates
Use test unit ID in development environment: PUBLIC_TEST_UNIT_ID_320_100

UIKit Implementation

In UIKit environment, implement banner ads using the AdropBanner class.

Basic Implementation

AdropBanner Initialization

String
required
Unit ID created in Ad Control Console

Load Ad

Call the load() method to request an ad after adding the banner to the screen.
Call load() when the banner is visible on screen. Loading when not visible may result in inaccurate impression measurements.

Set Context ID

You can set a Context ID for contextual targeting.

SwiftUI Implementation

In SwiftUI environment, implement banner ads using AdropBannerRepresented.

Basic Implementation

Delegate Handling

You can handle ad events through delegates.

Set Context ID


Objective-C Implementation

How to implement banner ads in Objective-C environment.

Basic Implementation

Set Context ID


Delegate Methods

The AdropBannerDelegate protocol handles ad lifecycle events.

onAdReceived (Required)

Called when ad is received successfully.

onAdFailedToReceive (Required)

Called when ad fails to load.
AdropErrorCode
Error code indicating the type of error. See Reference for details.

onAdImpression (Optional)

Called when ad is displayed on screen.

onAdClicked (Optional)

Called when user clicks on the ad.

onAdVideoStart (Optional)

Called when a video ad starts playing.

onAdVideoEnd (Optional)

Called when a video ad finishes playing.

Closure Callbacks

As an alternative to delegates, you can use closure-based callbacks.
If both a delegate and closures are set, both will be called.

Lifecycle Management

destroy()

When you no longer need the banner, call destroy() to release its resources — WebView, tracking, and any active video playback are torn down actively. destroy() is idempotent, so calling it multiple times is safe. The instance cannot be reused after destroy.
Skipping destroy() when the view controller deallocates leaves the WebView and related resources uncollected, which can cause memory leaks and performance degradation — especially impactful for video banners.

Ad Sizes

Banner ads require view size to match the size set in the unit.

Common Banner Sizes

UIKit

SwiftUI


Best Practices

1. Memory Management

Call destroy() when the view controller is deallocated to release banner resources.

2. Screen Visibility

Load ads when the banner is visible on screen.

3. Reuse the Banner Instance

Keep a single AdropBanner instance and call load() on it whenever you need a new ad. Do not create a new AdropBanner for every refresh. Recreating the banner for each ad request allocates a new WKWebView and its associated WebContent process each time. Under frequent refresh conditions — especially with video banners — this accumulates resource usage and can degrade rendering performance.
onAdReceived fires again on each subsequent load() call, so your existing delegate handles the new ad automatically.

4. Error Handling

Implement appropriate error handling when ad loading fails.

Test Unit IDs

Use the following test unit IDs during development and testing.

Usage Example


Video Playback Control

For video banner ads, you can manually control video playback using play() and pause().

play()

Resumes video playback. Call this when the banner becomes visible again — for example, after a popup is dismissed or the app returns from the background.

pause()

Pauses video playback. Call this when the banner is hidden by a popup or the app enters the background.

Example: Background/Foreground Handling

play() and pause() only affect video banner ads. They have no effect on image banners.

Custom Click Handling

You can take control of ad click behavior by using useCustomClick. When enabled, the SDK will not automatically open the destination URL on click, and you can handle it yourself.

useCustomClick

When useCustomClick is true, the SDK will not open the destination URL automatically when the ad is clicked. The onAdClicked delegate callback will still fire, and you can use the open() method or handle navigation yourself.

open()

Opens the destination URL of the ad. Can optionally pass a custom URL.

Batch Loading (loads)

Use AdropBanner.loads(...) to request multiple banner ads in a single batched call. This is useful for building carousels, paginated feeds, or prefetching a pool of ads.

Signature

Usage

Delegate Methods

The singular onAdReceived(_:) / onAdFailedToReceive(_:_:) callbacks are not invoked on the loads path. Use onAdsReceived(_:) / onAdsFailedToReceive(_:) as the sole batch signals.

Constants

Int
default:"5"
Upper bound on ads returned from a single loads(...) call.

Constraints

  • Maximum 5 ads per call. If the server returns more, only the first 5 are delivered.
  • Backfill is not applied. If no direct ads fill, onAdsFailedToReceive is called with ERROR_CODE_AD_NO_FILL regardless of backfill configuration.
  • Do not call destroy() inside onAdsReceived. Attach each banner to the view hierarchy first, then call destroy() when the view controller deallocates.
  • onAdsReceived fires as soon as ad data is applied, matching the single load() contract — the creative paints shortly after you add the banner to a view hierarchy.
  • Hold strong references to the returned banners (e.g., store them on the view controller). If they deallocate before being attached, they’re silently dropped.

Backfill Ads

When backfill ads are enabled, backfill ads are automatically loaded when direct ads are unavailable. Use the isBackfilled property to check if the ad is a backfill ad.
To use backfill ads, add the AdropAds-Backfill dependency. See Getting Started.

Next Steps

Native Ads

Implementing customizable native ads

Interstitial Ads

Implementing full-screen interstitial ads

Targeting Settings

Setting up user attributes and contextual targeting

Reference

Classes, delegates, error codes reference