Banner Placement
Banner Placement (Direct)
Banner placements display an anchored adaptive ad pinned to a fixed slot in your view hierarchy. The banner auto-resizes as the ad renders — pin it with Auto Layout (centre + bottom shown below) instead of a fixed-height frame so the JS engine can drive its own height. Use the direct integration when you don't use AdMob mediation.
- Swift
- Objective-C
import UIKit
import TeadsSDK
final class BannerViewController: UIViewController, TeadsAdPlacementEventsDelegate {
private var banner: TeadsAdPlacementBanner?
override func viewDidLoad() {
super.viewDidLoad()
// 1. Build the placement configuration
let config = TeadsAdPlacementBannerConfig(
articleUrl: URL(string: "https://yoursite.com/article")!,
widgetId: "MB_10", // Provided by your Teads account manager
installationKey: "YOUR_INSTALLATION_KEY"
)
// 2. Create the placement and load the ad
let placement = TeadsAdPlacementBanner(config, delegate: self)
banner = placement
do {
let adView = try placement.loadAd()
// 3. Pin it to your view hierarchy (do not use a fixed-height frame).
adView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(adView)
NSLayoutConstraint.activate([
adView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
adView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
adView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
} catch {
print("Failed to load banner: \(error)")
}
}
// MARK: - TeadsAdPlacementEventsDelegate
func adPlacement(
_ placement: TeadsAdPlacementIdentifiable?,
didEmitEvent event: TeadsAdPlacementEventName,
data: [String: Any]?
) {
// React to placement lifecycle events — see the Event Handling section below.
}
}
#import <UIKit/UIKit.h>
#import <TeadsSDK/TeadsSDK-Swift.h>
@interface BannerViewController : UIViewController <TeadsAdPlacementEventsDelegate>
@property (nonatomic, strong) TeadsAdPlacementBanner *banner;
@end
@implementation BannerViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 1. Create the placement directly with the Objective-C-friendly convenience
// initializer — all Swift default parameters must be passed explicitly
TeadsAdPlacementBanner *placement = [[TeadsAdPlacementBanner alloc] initWithArticleUrl:[NSURL URLWithString:@"https://yoursite.com/article"]
widgetId:@"MB_10" // Provided by your Teads account manager
installationKey:@"YOUR_INSTALLATION_KEY"
userId:nil
darkMode:NO
extId:nil
extSecondaryId:nil
obPubImp:nil
delegate:self];
self.banner = placement;
// 2. getAdView() is used instead of loadAd() — loadAd() returns a Swift-only
// "any UIView & DarkModeTogglable" existential that does not bridge to Objective-C
UIView *adView = [placement getAdView];
// 3. Pin it to your view hierarchy (do not use a fixed-height frame).
adView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:adView];
[NSLayoutConstraint activateConstraints:@[
[adView.leadingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor],
[adView.trailingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor],
[adView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]
]];
}
#pragma mark - TeadsAdPlacementEventsDelegate
- (void)adPlacement:(id<TeadsAdPlacementIdentifiable>)placement
didEmitEvent:(TeadsAdPlacementEventName)event
data:(NSDictionary<NSString *, id> *)data {
// React to placement lifecycle events — see the Event Handling section below.
}
@end
For production, articleUrl, widgetId, and installationKey will be unique values provided by your product manager. Contact your local account manager to obtain them.
The banner drives its own height from the JS engine. Don't constrain it to a fixed height — that will clip the creative as it resizes.
Lifecycle Events
The Banner placement uses the standard TeadsAdPlacementEventsDelegate. The events you'll typically observe on a banner:
| Event | Meaning |
|---|---|
loaded | Ad data was returned by the server |
ready | Ad is ready to be displayed |
rendered | Ad has been rendered on screen |
heightUpdated | Engine reports a new height — read it from data["height"] if you animate the slot |
viewed | Ad met viewability criteria |
clicked | User tapped the ad (the SDK opens the landing URL automatically) |
clickedOrganic | User tapped an organic recommendation; landing URL is in data["url"] |
failed | No ad to display — fall back to other content |
See Event Handling below for the full switch template covering all TeadsAdPlacementEventName cases.
If you use AdMob mediation instead, see the Mediation — Banner guide.