Banner Placement
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.
The official Teads SDK sample application includes working examples of this format. Use it for implementation examples and as a reference while you set up this placement.
Example
- 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 Placement Events Listener for the full event reference.
}
}
#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 Placement Events Listener for the full event reference.
}
@end
Best Practices
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.
The SDK opens the paid clicked URL. Do not navigate in that handler or the browser will open twice. Use it for tracking only. clickedOrganic, if the placement supports it, is publisher-owned — you still open that URL yourself.
Ad Lifecycle Listener
Implement TeadsAdPlacementEventsDelegate to observe playback, clicks, and viewability. See Placement Events Listener for the full event reference and error handling guide.
Checklist
- ✅ Ensure Brand Safety is enabled
- ✅ Ensure you comply with privacy legal requirements (GDPR/CCPA/GPP)
- ✅ Comply with app-ads.txt
- ✅ Implement proper error handling
- ✅ Test with the PIDs in Test PIDs and Configurations