Banner Ads
Banner ads are rectangular ad formats that occupy part of an app’s layout—often at the top or bottom of the screen or inline in scrollable content. They remain visible as users interact with the app, which allows uninterrupted gameplay or use, and can refresh automatically after a set period.
The following sections show you how to load and then show a banner ad.
Create a Banner Ad
To load a banner, create a CTBannerAd object that corresponds to your ad unit and call its loadAd method.
The banner ad will be displayed automatically after loaded; developers do not need to manually call the display function.
- Objective-C
objc
#import <CartySDK/CartySDK.h>
self.bannerAd = [[CTBannerAd alloc] init];
self.bannerAd.placementid = @"<your-placement-id>";
self.bannerAd.rootViewController = self;
self.bannerAd.bannerSize = CTBannerSizeType320x50;
self.bannerAd.delegate = self;
self.bannerAd.frame = self.adView.bounds;
[self.adView addSubview:self.bannerAd];- Swift
swift
import CartySDK
bannerAd = CTBannerAd()
bannerAd.placementid = "<your-placement-id>";
bannerAd.rootViewController = self;
bannerAd.delegate = self;
bannerAd.bannerSize = CTBannerSizeType320x50
bannerAd.frame = adView!.bounds;
adView!.addSubview(bannerAd)- About bannerSize
| Banner Format | Dimension |
|---|---|
| CTBannerSizeType320x50 | 320 x 50 |
| CTBannerSizeType320x100 | 320 x 100 |
| CTBannerSizeType300x250 | 300 x 250 |
Register for Callbacks
Implement CTBannerAdDelegate to listen to ad events.
- Objective-C
objc
- (void)CTBannerAdDidLoad:(nonnull CTBannerAd *)ad {
NSLog(@"Ad loaded");
}
- (void)CTBannerAdLoadFail:(nonnull CTBannerAd *)ad withError:(nonnull NSError *)error {
NSLog(@"Ad load fail: %@",error.localizedDescription);
}
- (void)CTBannerAdDidShow:(nonnull CTBannerAd *)ad {
NSLog(@"Ad did show");
}
- (void)CTBannerAdShowFail:(nonnull CTBannerAd *)ad withError:(nonnull NSError *)error {
NSLog(@"Ad show fail: %@",error.localizedDescription);
}
- (void)CTBannerAdDidClick:(nonnull CTBannerAd *)ad {
NSLog(@"Ad did click");
}
- (void)CTBannerAdDidClose:(nonnull CTBannerAd *)ad {
NSLog(@"Ad did close");
}- Swift
swift
func ctBannerAdDidLoad(_ ad: CTBannerAd) {
print("Ad loaded")
}
func ctBannerAdLoadFail(_ ad: CTBannerAd, withError error: any Error) {
print("Ad load fail \(error.localizedDescription)")
}
func ctBannerAdDidShow(_ ad: CTBannerAd) {
print("Ad did show")
}
func ctBannerAdShowFail(_ ad: CTBannerAd, withError error: any Error) {
print("Ad show fail \(error.localizedDescription)")
}
func ctBannerAdDidClick(_ ad: CTBannerAd) {
print("Ad did click")
}
func ctBannerAdDidClose(_ ad: CTBannerAd) {
print("Ad did close")
}Other
Mute
Make sure make this call before load
- Objective-C
objc
self.bannerAd.isMute = YES;- Swift
swift
bannerAd.isMute = true