Use banner ad placements to configure native ads.
Please visit here to view the support scope of this feature.
If the dashboard chooses Taku rendering (SDK rendering), the UI elements cannot be set up with custom layouts. You only need to correctly specify the banner container size without modifying the code, and you can skip the following steps.
If the dashboard chooses self-rendering, additional code integration is required. Please read the following notes before proceeding with code integration.
If your dashboard configuration uses a self-rendering solution, please note the following:
When you get UI elements and configure the layout yourself, if the show callback is not triggered when calling display, it means that your rendered UI elements are insufficient or there are layout issues, causing the ad platform to determine it as an invalid display. You need to adjust according to the actual situation to meet the ad platform requirements.
If you don't implement self-rendering to return an ad View in the code, the SDK's built-in layout style will be used for rendering by default.
When you set self-rendering to return an ad View in the code, the ad background is fully transparent by default.
For the handling of mainImageView or mediaView in the diagram below, their layouts are consistent. When mediaView has a value, layout mediaView and display it on top.
Some ad elements must be rendered, while others are optional. Please refer to the end of this article for details.
Ad element fields may not have values, so null checking is required before use.
#import <Masonry/Masonry.h>
- (void)showBanner {
// Check if the ad is ready before displaying
if ([[ATAdManager sharedManager] bannerAdReadyForPlacementID:@"your banner placementID"]) {
// Remove any existing old BannerView
NSInteger tag = 3333;
[[self.view viewWithTag:tag] removeFromSuperview];
//Retrieve banner view
ATShowConfig *showConfig = ATShowConfig.new;
// If there's no scene configuration, use default scene by passing an empty string
showConfig.scene = @"your scene id";
// Pass-through parameters when displaying
showConfig.showCustomExt = @"testShowCustomExt";
__weak __typeof(self)weakSelf = self;
ATBannerView *bannerView = [[ATAdManager sharedManager] retrieveBannerViewForPlacementID:@"your banner ad id"
config:showConfig
nativeMixBannerViewBlock:^(ATNativeBannerView * _Nonnull nativeBannerView) {
// When Taku backend chooses self-rendering, you need to set constraints for ATNativeBannerView. This callback won't be triggered if Taku rendering is selected
[weakSelf developerSlefRender:nativeBannerView];
}];
if (bannerView != nil) {
bannerView.delegate = self;
bannerView.presentingViewController = self;
bannerView.translatesAutoresizingMaskIntoConstraints = NO;
bannerView.tag = tag;
[self.view addSubview:bannerView];
//Layout banner
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:bannerView attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:.0f]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0f constant:CGRectGetHeight([UIApplication sharedApplication].statusBarFrame) + CGRectGetHeight(self.navigationController.navigationBar.frame)]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:_adSize.width]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:_adSize.height]];
} else {
NSLog(@"Banner ad's not ready for placementID:%@", @"your banner placementID");
}
}
- (void)developerSlefRender:(ATNativeBannerView *)nativeBannerView {
// Only render part as an example
[nativeBannerView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(350);
make.height.mas_equalTo(150);
make.center.mas_equalTo(nativeBannerView.superview);
}];
[nativeBannerView.textLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(nativeBannerView);
make.right.mas_equalTo(nativeBannerView);
make.height.mas_equalTo(30);
make.bottom.mas_equalTo(nativeBannerView.mas_bottom).offset(-5);
}];
[nativeBannerView.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(nativeBannerView);
make.right.mas_equalTo(nativeBannerView);
make.height.mas_equalTo(30);
make.bottom.mas_equalTo(nativeBannerView.textLabel.mas_top).offset(-5);
}];
// Add click registration controls
NSMutableArray *regisArray = [NSMutableArray array];
if (nativeBannerView.textLabel) {
[regisArray addObject:nativeBannerView.textLabel];
}
if (nativeBannerView.titleLabel) {
[regisArray addObject:nativeBannerView.titleLabel];
}
[nativeBannerView registerClickableViewArray:regisArray];
}
For recommended rendering components, if you choose not to render them, you need to confirm whether the ad platform's display exposure callback is triggered normally.
API Element | Type | Rendering Required | Rendering Requirement Description |
---|---|---|---|
titleLabel (corresponds to title) | UILabel | Recommended | Ad title, recommended to display |
textLabel (corresponds to mainText) | UILabel | Optional | Ad description text, depends on UI space |
ctaLabel (corresponds to ctaText) | UILabel | Optional | Call-to-action button text |
advertiserLabel (corresponds to advertiser) | UILabel | Conditionally Required | Must render when using Yandex platform |
iconImageView (corresponds to iconUrl/icon) | UIImageView | Recommended | Ad icon, recommended to display |
logoImageView (corresponds to logoUrl/logo) | UIImageView | Required | Platform logo must be displayed |
mainImageView (corresponds to imageUrl/mainImage) | UIImageView | Recommended | Need to confirm display exposure callback if not rendered |
adImageView | UIImageView | Recommended | Ad "Ad" identifier image |
ratingLabel (corresponds to rating) | UILabel | Optional | Rating information |
sponsorLabel | UILabel | Optional | Sponsor information |
domainLabel (corresponds to domain) | UILabel | Conditionally Required | Must render only for Yandex platform |
warningLabel (corresponds to warning) | UILabel | Conditionally Required | Must render only for Yandex platform |
dislikeButton | UIButton | Recommended | Universal close button, recommended to keep |
netWorkMediaView (corresponds to videoUrl) | UIView | Recommended | Recommended to add for video ads, need to confirm display exposure callback if not rendered |
netWorkMediaBackView | UIView | Optional | Background of media view, only created when there's no MediaView and main image mainImageView |
netWorkOptionView | UIView | Recommended | Ad platform option view, recommended to keep |