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
String
required
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.
Lifecycle Management
destroy()
When you no longer need the banner, calldestroy() 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.
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
Calldestroy() 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 singleAdropBanner 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 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
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,
onAdsFailedToReceiveis called withERROR_CODE_AD_NO_FILLregardless of backfill configuration. - Do not call
destroy()insideonAdsReceived. Attach each banner to the view hierarchy first, then calldestroy()when the view controller deallocates. 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