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.
#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];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.
- (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");
}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
self.bannerAd.isMute = YES;bannerAd.isMute = trueClient-side bidding
After the ad loads successfully, you can obtain ecpm via the following API.
self.bannerAd.ecpmbannerAd.ecpmAfter winning the ad bid, call bidWin and pass in the second-highest bid from this bid.
[self.bannerAd bidWin:@"second_pirce"];bannerAd.bidWin("second_pirce");After an ad is lost, bidWin is called with the highest bid received in the auction.
[self.bannerAd bidLoss:@"top_price"];bannerAd.bidLoss("top_price")