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_100UIKit Implementation
In UIKit environment, implement banner ads using theAdropBanner class.
Basic Implementation
AdropBanner Initialization
Unit ID created in Ad Control Console
Load Ad
Call theload() method to request an ad after adding the banner to the screen.
Set Context ID
You can set a Context ID for contextual targeting.SwiftUI Implementation
In SwiftUI environment, implement banner ads usingAdropBannerRepresented.
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
TheAdropBannerDelegate protocol handles ad lifecycle events.
onAdReceived (Required)
Called when ad is received successfully.onAdFailedToReceive (Required)
Called when ad fails to load.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.
Ad Sizes
Banner ads require view size to match the size set in the unit.Common Banner Sizes
| Size | Use Case |
|---|---|
| 320 x 50 | Small banner |
| 320 x 100 | Large banner |
| 16:9 ratio | Video banner |
UIKit
SwiftUI
Best Practices
1. Memory Management
Remove the banner when the view controller is deallocated.2. Screen Visibility
Load ads when the banner is visible on screen.3. Reuse
Callload() again to reuse the same banner instance.
4. Error Handling
Implement appropriate error handling when ad loading fails.Test Unit IDs
Use the following test unit IDs during development and testing.| Ad Type | Test Unit ID | Size |
|---|---|---|
| Banner (320x50) | PUBLIC_TEST_UNIT_ID_320_50 | 320 x 50 |
| Banner (320x100) | PUBLIC_TEST_UNIT_ID_320_100 | 320 x 100 |
| Carousel Banner | PUBLIC_TEST_UNIT_ID_CAROUSEL | Variable |
| Banner Video (16:9) | PUBLIC_TEST_UNIT_ID_BANNER_VIDEO_16_9 | 16:9 ratio |
| Banner Video (9:16) | PUBLIC_TEST_UNIT_ID_BANNER_VIDEO_9_16 | 9:16 ratio |
Usage Example
Video Playback Control
For video banner ads, you can manually control video playback usingplay() 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 usinguseCustomClick. When enabled, the SDK will not automatically open the destination URL on click, and you can handle it yourself.
useCustomClick
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)
UseAdropBanner.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
| Method | When it fires |
|---|---|
onAdsReceived(_:) | Batch delivered. Each AdropBanner already has the delegate attached and ad data applied. |
onAdsFailedToReceive(_:) | Request rejected, network failure, or no fillable ads were returned (ERROR_CODE_AD_NO_FILL). |
onAdClicked / onAdImpression / onAdVideoStart / onAdVideoEnd | Fire on each returned banner just like a single load(). |
Constants
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,
onAdsFailedToReceiveis called withERROR_CODE_AD_NO_FILLregardless of backfill configuration. onAdsReceivedfires as soon as ad data is applied, matching the singleload()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 theisBackfilled 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