Menu

Draw ads

1. Introduction

Draw advertisement Native advertising is a special type of rendering, which is generally displayed in full-screen mode and is suitable for full-screen page-turning information flow ads. Among them, Draw advertising implementation rendering methods include self-rendering and template-type ads. The general effect of Draw ads is as follows: native_draw_ad

1.1 Integration suggestions

1. Load ads

    • Execute loading ads through loadADWithPlacementID, please call in advance The loading method performs an ad request. For example, the ad can be preloaded after the screen is opened so that it can be displayed quickly when the ad needs to be triggered.
    • When loading, pass in The size is the width and height of the screen.

2. Display ads

    • To obtain the advertising object, you can call getNativeAdOfferWithPlacementID after the didFinishLoadingADWithPlacementID callback to obtain the advertisement
    • You can use getCurrentNativeAdRenderType in the ATNativeADView class to determine whether the advertisement is a template rendering type advertisement
    • ATNativeAdRenderSelfRender Ads are provided to developers in the form of source materials for rendering, except that some advertising platforms directly provide mediaview for large images and videos
    • Native ads can only be displayed in the same place at the same time. Otherwise, the Native ad displayed at the beginning will not be displayed or clicked normally.
    • In the process of integrating Native advertising, the developer selects the material elements that need to be displayed. After display, the didShowNativeAdInAdView callback is triggered to indicate effective display
    • According to the instructions for displaying ads below, complete the display logic of the ads. The main operations include:
      1. Get the ATNativeAdOffer material object;
      2. Generate the ATNativeADView container object;
      3. If there is a template , large pictures, videos and other materials require mediaview and are added to the container view;
      4. Register click events of related controls;
      5. Add Draw advertising video view Wait for the UI controls to come to the view
      6. Render the native ad layout;
      7. Place The ATNativeADView container object is displayed.

1.2 Notes

    • To ensure faster After obtaining an advertisement and guaranteeing a higher price, it is recommended to perform the next advertisement loading after each acquisition of an advertisement. Do not execute the advertisement loading method in the didFailToLoadADWithPlacementID callback, otherwise it will cause a lot of useless requests and may cause Causing application lag.
    • In order to facilitate the use of funnel reports to analyze advertising scenarios, it is recommended to call entryNativeScenarioWithPlacementID when displaying native ads to record scenario statistics
    • Suggestions Configure the preset strategy: improve the ad loading effect of the first cold start. For specific instructions and access tutorials, see SDK preset strategy usage instructions.

2 API Description

2.1 Loading ads

ATAdManager: Native advertising management class

MethodDescription
sharedManagerGet ATAdManager singleton object
loadADWithPlacementID: extra: delegate:Native ads loading method
placementId: TopOn's advertising slot id
extra: local configuration parameters
delegate: proxy object

Sample code:

#import <AnyThinkNative/AnyThinkNative.h>

- (void)loadAd {
    /*
        Template AD size, through the advertising platform, the advertising platform will return a similar size of the optimal template AD, 
         if there is no specific size requirements, you can pass the height 0, by the platform adaptation width to return the appropriate height.
    */
    CGSize size = CGSizeMake(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height);
    NSDictionary *extra = @{
        kATExtraInfoNativeAdSizeKey:[NSValue valueWithCGSize:size],
    };
    [[ATAdManager sharedManager] loadADWithPlacementID:@"your Native placement id" extra:extra delegate:self];
}

2.2 Display ads

2.2.1 Implement Custom Native Ad View

To display a Native ad, you need to define a custom view, which is responsible for native Self-rendering ad display requires initializing the display controls.

As shown below:

@interface ATNativeSelfRenderView : UIView

@property(nonatomic, strong) UILabel *advertiserLabel;
@property(nonatomic, strong) UILabel *textLabel;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UILabel *ctaLabel;
@property(nonatomic, strong) UILabel *ratingLabel;
@property(nonatomic, strong) UIImageView *iconImageView;
@property(nonatomic, strong) UIImageView *mainImageView;
@property(nonatomic, strong) UIImageView *logoImageView;
@property(nonatomic, strong) UIButton *dislikeButton;

@property(nonatomic, strong) UIView *mediaView;

- (instancetype) initWithOffer:(ATNativeAdOffer *)offer;

@end

Here, your ad view needs to do two things:

1) Create the UI elements that the ad view needs to display , assign the obtained material to the UI element:

- (void)addView{    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.font = [UIFont boldSystemFontOfSize:18.0f];
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.textAlignment = NSTextAlignmentLeft;
    self.titleLabel.userInteractionEnabled = YES;
    [self addSubview:self.titleLabel];
    ......
}

- (void)setupUI{
 
    if (self.nativeAdOffer.nativeAd.icon) {
            self.iconImageView.image = self.nativeAdOffer.nativeAd.icon;
    } else {
            [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:self.nativeAdOffer.nativeAd.iconUrl]];
    }
 
    self.advertiserLabel.text = self.nativeAdOffer.nativeAd.advertiser;
    ......
}

2 ) Layout of UI elements

In our sample code, we use Masonry layout of UI elements.

-(void) makeConstraintsForSubviews {
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(100);
        make.right.equalTo(self).offset(-40);
        make.height.equalTo(@20);
        make.top.equalTo(self).offset(20);
    }];
    ......
}

You can also use struts&springs layout technology. When using this method, it is recommended You override the layoutSubviews method and set frames for your subviews. It's entirely up to you which layout technique you use, and you can choose whatever suits you.

2.2.2 Custom View displays Native

Native advertising integration process:

1. Get Draw advertisement ATNativeAdOffer object

ATNativeAdOffer *offer = [[ATAdManager sharedManager] getNativeAdOfferWithPlacementID:@"your Native placement id"];

2. Generate a container for native display

ATNativeADConfiguration *config = [[ATNativeADConfiguration alloc] init];
config.ADFrame = CGRectMake(0, kNavigationBarHeight, kScreenW, kScreenH - kNavigationBarHeight);
// Here, as the default value, you can use [nativeADView getMediaView] in ATNativeADView to get mediaView for dynamic setting constraints.
config.mediaViewFrame = CGRectMake(0, kNavigationBarHeight + 150.0f, kScreenW, kScreenH - kNavigationBarHeight - 150);
config.delegate = self;
config.rootViewController = self;

ATNativeADView *nativeADView = [[ATNativeADView alloc] initWithConfiguration:config currentOffer:offer placementID:@"your Native placement id"];

3. Get mediaview, which is used to display videos, pictures, etc. from third-party advertising platforms. If not provided, nil is returned.

UIView *mediaView = [nativeADView getMediaView];

4. Register click event

[nativeADView registerClickableViewArray:array];

5. Add draw UI materials to self-rendering selfRenderView

[selfRenderView addSubview:nativeADView.videoAdView];
[selfRenderView addSubview:nativeADView.dislikeDrawButton];
[selfRenderView addSubview:nativeADView.adLabel];
[selfRenderView addSubview:nativeADView.logoDrawImageView];
[selfRenderView addSubview:nativeADView.logoADImageView];

nativeADView.videoAdView.frame = CGRectMake(0, kNavigationBarHeight + 50.0f, kScreenW, kScreenH - kNavigationBarHeight - 50);
nativeADView.dislikeDrawButton.frame = CGRectMake(kScreenW - 50, kNavigationBarHeight + 80.0f , 50,50);
nativeADView.adLabel.frame = CGRectMake(kScreenW - 50, kNavigationBarHeight + 150.0f, kScreenW, 50);
nativeADView.logoDrawImageView.frame = CGRectMake(kScreenW - 50, kNavigationBarHeight + 200.0f, 50, 50);
nativeADView.logoADImageView.frame = CGRectMake(kScreenW - 50, kNavigationBarHeight + 250.0f, 50, 50);

6. Render ads

[offer rendererWithConfiguration:config selfRenderView:selfRenderView nativeADView:nativeADView];

Complete display code

-(void) showAD {
    
    ATNativeADConfiguration *config = [[ATNativeADConfiguration alloc] init];
    config.ADFrame = CGRectMake(0, kNavigationBarHeight, kScreenW, kScreenH - kNavigationBarHeight);
    config.mediaViewFrame = CGRectMake(0, kNavigationBarHeight + 150.0f, kScreenW, kScreenH - kNavigationBarHeight - 150);
    config.delegate = self;
    config.rootViewController = self;

    // Get advertising material
    ATNativeAdOffer *offer = [[ATAdManager sharedManager]
                getNativeAdOfferWithPlacementID:@"your Native placement id"];

    // Native ads display container view
    ATNativeADView *nativeADView = [[ATNativeADView alloc] initWithConfiguration:config currentOffer:offer placementID:@"your Native placement id"];

    UIView *mediaView = [nativeADView getMediaView];

    // Self-rendering view 
    ATNativeSelfRenderView *selfRenderView = [[ATNativeSelfRenderView alloc] initWithOffer:offer];

    // Register click event
    NSMutableArray *array = [@[selfRenderView.iconImageView] mutableCopy];
    if (mediaView) {
        [array addObject:mediaView];
        // Where hierarchical occlusion is involved, developers can actually make adjustments  
        [selfRenderView addSubview:mediaView]; 
        
        [mediaView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(selfRenderView);
            make.top.equalTo(selfRenderView.mainImageView.mas_top);
        }];
    }
    [nativeADView registerClickableViewArray:array];

    // Adds the draw UI material to the self-rendered selfRenderView
    [selfRenderView addSubview:nativeADView.videoAdView];
    [selfRenderView addSubview:nativeADView.dislikeDrawButton];
    [selfRenderView addSubview:nativeADView.adLabel];
    [selfRenderView addSubview:nativeADView.logoDrawImageView];
    [selfRenderView addSubview:nativeADView.logoADImageView];

    nativeADView.videoAdView.frame = CGRectMake(0, kNavigationBarHeight + 50.0f, kScreenW, kScreenH - kNavigationBarHeight - 50);
    nativeADView.dislikeDrawButton.frame = CGRectMake(kScreenW - 50, kNavigationBarHeight + 80.0f , 50,50);
    nativeADView.adLabel.frame = CGRectMake(kScreenW - 50, kNavigationBarHeight + 150.0f, kScreenW, 50);
    nativeADView.logoDrawImageView.frame = CGRectMake(kScreenW - 50, kNavigationBarHeight + 200.0f, 50, 50);
    nativeADView.logoADImageView.frame = CGRectMake(kScreenW - 50, kNavigationBarHeight + 250.0f, 50, 50);

    // Bind a self-rendering view control
    ATNativePrepareInfo *info = [ATNativePrepareInfo loadPrepareInfo:^(ATNativePrepareInfo * _Nonnull prepareInfo) {
        prepareInfo.textLabel = selfRenderView.textLabel;
        ......
    }];
    [nativeADView prepareWithNativePrepareInfo:info];

     // render and show Draw ad
     [offer rendererWithConfiguration:config selfRenderView:selfRenderView nativeADView:nativeADView];
      [self.view addSubview:nativeADView];
}

2.2.3 Self-rendering creative description

ATNativeAdOffer.nativeAd: Creative object, the following materials may be null, because some advertising platforms may not have all the material information. Another point to note is to pay attention to Display delegate callback, If the display callback is not triggered, it may be displayed as an invalid display on the third-party platform and needs to be redesigned.

UI elements include:

UIReturn typeDescription
titleNSStringAd title
mainTextNSStringAd description
ctaTextNSStringAd CTA button text
advertiserNSStringAdvertiser name
iconUrlNSStringAd icon url
logoUrlNSStringAdvertising platform logo url
imageUrlNSStringLarge image url
imageListNSArrayPicture array
mainImageWidthCGFloatLarge image width
mainImageHeightCGFloatLarge picture height
iconUIImageAdvertising icon image
logoUIImageAdvertising platform logo image
mainImageUIImageLarge image
isVideoContentsBOOLWhether it is a video ad
videoUrlNSStringVideo url
videoDurationNSIntegerVideo duration
videoAspectRatioCGFloatVideo size Scale
interactionTypeNSIntegerAdvertising Supported jump types
mediaExtNSDictionaryMedia extension data
sourceNSStringApplication source, market
ratingNSNumberAd's rating
commentNumNSIntegerNumber of comments
appSizeNSIntegerAd installation package size
appPriceNSStringapp purchase price
domainNSStringDomain name (only supported by the Yandex platform)
warningNSStringWarning (only supported by Yandex platform)

For video ads, there is a media view playing the video, which is obtained through the following API. Some third parties display their cover image in the media view, and some display both media view and image view. .

UIView *mediaView = [nativeADView getMediaView];

ATImageLoader: provided by the SDK, used to display network images (optional)

MethodParametersDescription
loadImageWithURLNSURLDisplay network pictures
URL: network picture url

2.3 Scene statistics

MethodDescription
entryNativeScenarioWithPlacementID:scene:The corresponding advertising space enters the business scene cache status statistics placementId: advertising space Id scene: advertising display scene, the scene parameters can be created from the background, there is no Pass empty@"" For usage, please refer to Business scenario cache status statistics

2.4 Delegate callback

ATAdLoadingDelegate delegate method

MethodDescription
didFinishLoadingADWithPlacementID:Corresponds to Advertising slot advertisement Loading success callback
placementId: Advertising slot Id
didFailToLoadADWithPlacementID: error:corresponds to Advertising slot advertisement loading failure callback
placementId: Advertising slot Id
error: Advertisement loading failure information

ATNativeADDelegateProxy method

MethodDescription
didShowNativeAdInAdView: placementID: extra: Native ads are displayed successfully
didClickNativeAdInAdView: placementID: extra:Native ad click
didStartPlayingVideoInAdView: placementID: extra:Native video ad starts playing
didEndPlayingVideoInAdView: placementID: extra:Native video ad ends playing
didEnterFullScreenVideoInAdView: placementID: extra :Native enter full-screen video advertising
didExitFullScreenVideoInAdView: placementID: extra:Native exit full-screen video advertising
didTapCloseButtonInAdView: placementID: extra:Close button click in Native ads
didLoadSuccessDrawWith: placementID: extra:Native draw ad loaded successfully
didDeepLinkOrJumpInAdView: placementID: extra: result:Whether the native ad click jump is in Deeplink form, currently only Ad returns for TopOn Adx
didCloseDetailInAdView: placementID: extra:Native ad click to close the details page
extra: Extended parameter reference Documentation

Sample code:

#pragma mark - delegate with loading
-(void) didFinishLoadingADWithPlacementID:(NSString *)placementID {
    NSLog(@"ATDrawListViewController:: didFinishLoadingADWithPlacementID:%@", placementID);
}

-(void) didFailToLoadADWithPlacementID:(NSString *)placementID error:(NSError *)error {
    NSLog(@"ATDrawListViewController:: didFailToLoadADWithPlacementID:%@ error:%@", placementID, error);
}

#pragma mark - delegate with native ad
-(void) didStartPlayingVideoInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra{
    NSLog(@"ATDrawListViewController:: didStartPlayingVideoInAdView:placementID:%@with extra: %@", placementID,extra);
}

-(void) didEndPlayingVideoInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra{
    NSLog(@"ATDrawListViewController:: didEndPlayingVideoInAdView:placementID:%@ extra: %@", placementID,extra);
}

-(void) didClickNativeAdInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra{
    NSLog(@"ATDrawListViewController:: didClickNativeAdInAdView:placementID:%@ with extra: %@", placementID,extra);
}

- (void) didDeepLinkOrJumpInAdView:(ATNativeADView *)adView placementID:(NSString *)placementID extra:(NSDictionary *)extra result:(BOOL)success {
    NSLog(@"ATDrawListViewController:: didDeepLinkOrJumpInAdView:placementID:%@ with extra: %@, success:%@", placementID,extra, success ? @"YES" : @"NO");
}

-(void) didShowNativeAdInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra{
    NSLog(@"ATDrawListViewController:: didShowNativeAdInAdView:placementID:%@ with extra: %@", placementID,extra);
}

-(void) didEnterFullScreenVideoInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra{
    NSLog(@"ATDrawListViewController:: didEnterFullScreenVideoInAdView:placementID:%@", placementID);
}

-(void) didExitFullScreenVideoInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra{
    NSLog(@"ATDrawListViewController:: didExitFullScreenVideoInAdView:placementID:%@", placementID);
}

-(void) didTapCloseButtonInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra {
    NSLog(@"ATDrawListViewController:: didTapCloseButtonInAdView:placementID:%@ extra:%@", placementID, extra);
}

- (void)didCloseDetailInAdView:(ATNativeADView *)adView placementID:(NSString *)placementID extra:(NSDictionary *)extra {
    NSLog(@"ATDrawListViewController:: didCloseDetailInAdView:placementID:%@ extra:%@", placementID, extra);
}

2.5 Other API

Method Description
getNativeValidAdsForPlacementID:Query all cached information of this ad slot. The first item in the array is the ad data to be displayed.
placementId: the advertising slot Id to be queried
// Query all cache information for the AD space
NSArray *array = [[ATAdManager sharedManager] getNativeValidAdsForPlacementID:@"your native placementID"];
NSLog(@"ValidAds.count:%ld--- ValidAds:%@",array.count,array);

3. Sample code

ATNativeSelfRenderView.h

#import <UIKit/UIKit.h>
#import <AnyThinkNative/AnyThinkNative.h>


NS_ASSUME_NONNULL_BEGIN

@interface ATNativeSelfRenderView : UIView

@property(nonatomic, strong) UILabel *advertiserLabel;
@property(nonatomic, strong) UILabel *textLabel;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UILabel *ctaLabel;
@property(nonatomic, strong) UILabel *ratingLabel;
@property(nonatomic, strong) UIImageView *iconImageView;
@property(nonatomic, strong) UIImageView *mainImageView;
@property(nonatomic, strong) UIImageView *logoImageView;
@property(nonatomic, strong) UIButton *dislikeButton;

@property(nonatomic, strong) UIView *mediaView;

- (instancetype) initWithOffer:(ATNativeAdOffer *)offer;

@end

NS_ASSUME_NONNULL_END

ATNativeSelfRenderView.m

#import "ATNativeSelfRenderView.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/SDWebImage.h>

@interface ATNativeSelfRenderView()

@property(nonatomic, strong) ATNativeAdOffer *nativeAdOffer;

@end


@implementation ATNativeSelfRenderView

- (instancetype) initWithOffer:(ATNativeAdOffer *)offer{

    if (self = [super init]) {
        
        _nativeAdOffer = offer;
        
        [self addView];
        [self makeConstraintsForSubviews];
        
        [self setupUI];
    }
    return self;
}

- (void)addView{
    
    self.advertiserLabel = [[UILabel alloc]init];
    self.advertiserLabel.font = [UIFont boldSystemFontOfSize:15.0f];
    self.advertiserLabel.textColor = [UIColor blackColor];
    self.advertiserLabel.textAlignment = NSTextAlignmentLeft;
    self.advertiserLabel.userInteractionEnabled = YES;
    [self addSubview:self.advertiserLabel];
        
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.font = [UIFont boldSystemFontOfSize:18.0f];
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.textAlignment = NSTextAlignmentLeft;
    self.titleLabel.userInteractionEnabled = YES;

    [self addSubview:self.titleLabel];
    
    self.textLabel = [[UILabel alloc]init];
    self.textLabel.font = [UIFont systemFontOfSize:15.0f];
    self.textLabel.textColor = [UIColor blackColor];
    self.textLabel.userInteractionEnabled = YES;

    [self addSubview:self.textLabel];
    
    self.ctaLabel = [[UILabel alloc]init];
    self.ctaLabel.font = [UIFont systemFontOfSize:15.0f];
    self.ctaLabel.textColor = [UIColor blackColor];
    self.ctaLabel.userInteractionEnabled = YES;

    [self addSubview:self.ctaLabel];

    self.ratingLabel = [[UILabel alloc]init];
    self.ratingLabel.font = [UIFont systemFontOfSize:15.0f];
    self.ratingLabel.textColor = [UIColor blackColor];
    self.ratingLabel.userInteractionEnabled = YES;

    [self addSubview:self.ratingLabel];
    
    self.iconImageView = [[UIImageView alloc]init];
    self.iconImageView.layer.cornerRadius = 4.0f;
    self.iconImageView.layer.masksToBounds = YES;
    self.iconImageView.contentMode = UIViewContentModeScaleAspectFit;
    self.iconImageView.userInteractionEnabled = YES;
    [self addSubview:self.iconImageView];
    
    
    self.mainImageView = [[UIImageView alloc]init];
    self.mainImageView.contentMode = UIViewContentModeScaleAspectFit;
    self.mainImageView.userInteractionEnabled = YES;
    [self addSubview:self.mainImageView];
    
    self.logoImageView = [[UIImageView alloc]init];
    self.logoImageView.contentMode = UIViewContentModeScaleAspectFit;
    self.logoImageView.userInteractionEnabled = YES;

    [self addSubview:self.logoImageView];
    
    self.dislikeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    UIImage *closeImg = [UIImage imageNamed:@"icon_webview_close" inBundle:[NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"AnyThinkSDK" ofType:@"bundle"]] compatibleWithTraitCollection:nil];
    
    self.dislikeButton.backgroundColor = randomColor;
    
    [self.dislikeButton setImage:closeImg forState:0];
    [self addSubview:self.dislikeButton];
}


- (void)setupU I{
    if (self.nativeAdOffer.nativeAd.icon) {
        self.iconImageView.image = self.nativeAdOffer.nativeAd.icon;
    } else {
        [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:self.nativeAdOffer.nativeAd.iconUrl]];
    }

    if (self.nativeAdOffer.nativeAd.mainImage) {
        self.mainImageView.image = self.nativeAdOffer.nativeAd.mainImage;
    } else {
        [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:self.nativeAdOffer.nativeAd.imageUrl]];=
    }
    
    if (self.nativeAdOffer.nativeAd.logoUrl.length) {
        [self.logoImageView sd_setImageWithURL:[NSURL URLWithString:self.nativeAdOffer.nativeAd.logoUrl]];
    } else if (self.nativeAdOffer.nativeAd.logo) {
        self.logoImageView.image = self.nativeAdOffer.nativeAd.logo;
    } else { // All of these are nil, set the default platform logo using networkFirmID.
        
        if (self.nativeAdOffer.networkFirmID == 15) {//TT(CSJ), as an example only, this is not mandatory
            self.logoImageView.image = [UIImage imageNamed:@"tt_ad_logo_new"];
        }
    }
        
    self.advertiserLabel.text = self.nativeAdOffer.nativeAd.advertiser;
    self.titleLabel.text = self.nativeAdOffer.nativeAd.title;
    self.textLabel.text = self.nativeAdOffer.nativeAd.mainText;
    self.ctaLabel.text = self.nativeAdOffer.nativeAd.ctaText;
   
}

-(void) makeConstraintsForSubviews {
    
    self.backgroundColor = randomColor;

    self.titleLabel.backgroundColor = randomColor;
    
    self.textLabel.backgroundColor = randomColor;
    
    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.equalTo(@25);
        make.bottom.equalTo(self).equalTo(@-5);
        make.left.equalTo(self).equalTo(@5);
    }];
    
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(100);
        make.right.equalTo(self).offset(-40);
        make.height.equalTo(@20);
        make.top.equalTo(self).offset(20);
    }];
    
    [self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(100);
        make.right.equalTo(self).offset(-40);
        make.height.equalTo(@20);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
    }];
    
    [self.ctaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.textLabel.mas_bottom).equalTo(@5);
        make.width.equalTo(@100);
        make.height.equalTo(@40);
        make.left.equalTo(self.textLabel.mas_left);
    }];
    
    [self.ratingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ctaLabel.mas_right).offset(20);
        make.height.equalTo(@40);
        make.top.equalTo(self.ctaLabel.mas_top).offset(0);
        make.width.equalTo(@20);
    }];

    [self.advertiserLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@30);
        make.right.equalTo(self).equalTo(@-5);
        make.left.equalTo(self.ctaLabel.mas_right).offset(50);
        make.bottom.equalTo(self.iconImageView.mas_bottom);
    }];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(20);
        make.height.width.equalTo(@75);
        make.top.equalTo(self).offset(20);
    }];
    
    [self.mainImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(20);
        make.right.equalTo(self).offset(-20);
        make.top.equalTo(self.iconImageView.mas_bottom).offset(25);
        make.bottom.equalTo(self).offset(-5);
    }];

    [self.dislikeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.equalTo(@30);
        make.top.equalTo(self).equalTo(@5);
        make.right.equalTo(self.mas_right).equalTo(@-5);
    }];
    
}
@end

ATNativeSelfRenderViewController class

#import "ATDrawListViewController.h"

@interface ATDrawListViewController()<ATNativeADDelegate>

@property(nonatomic) ATNativeADView *adView;
@property(nonatomic, strong) ATNativeSelfRenderView *nativeSelfRenderView;

@end

@implementation ATDrawListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
     CGSize size = CGSizeMake(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height); 
     NSDictionary *extra = @{ kATExtraInfoNativeAdSizeKey:[NSValue valueWithCGSize:size], }; 
     [[ATAdManager sharedManager] loadADWithPlacementID:@"your Native placement id" extra:extra delegate:self];
}

- (void)entryAdScenario {
    /* To collect scene arrival rate statistics, you can view related information https://docs.toponad.com/#/zh-cn/ios/NetworkAccess/scenario/scenario 
    Call the "Enter AD scene" method when an AD trigger condition is met, such as: 
    ** The scenario is a pop-up AD after the cleanup, which is called at the end of the cleanup. 
    * 1、Call entryXXX to report the arrival of the scene. 
    * 2、Call xxRewardedVideoReadyForPlacementID. 
    * 3、Call showXX to show AD view. 
    * (Note the difference between auto and manual) */
    [[ATAdManager sharedManager] entryNativeScenarioWithPlacementID:@"your Native placement id" scene:@"your scenarioID"];
}

- (void)showAD {
     
    [self entryAdScenario];
    
    if ([[ATAdManager sharedManager] nativeAdReadyForPlacementID:@"your Native placement id"]) {
    
        ATNativeADConfiguration *config = [[ATNativeADConfiguration alloc] init];
        config.ADFrame = CGRectMake(.0f, 64.0f, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height);
        config.mediaViewFrame = CGRectMake(0, 120.0f, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height - 120.0f);
        config.delegate = self;
        config.rootViewController = self;

        // Get advertising material
        ATNativeAdOffer *offer = [[ATAdManager sharedManager] getNativeAdOfferWithPlacementID:@"your Native placement id" scene:@"your scenarioID"];

         // Create a self-rendering view and use the offer material to assign values
        ATNativeSelfRenderView *selfRenderView = [[ATNativeSelfRenderView alloc] initWithOffer:offer];

        // Create a native AD display container view
        ATNativeADView *nativeADView = [[ATNativeADView alloc] initWithConfiguration:config currentOffer:offer placementID:@"your Native placement id"];

        // Get mediaView
        UIView *mediaView = [nativeADView getMediaView];

        // Register the click event, it is best not to add the superview of the information flow as a whole to the click event, 
        // otherwise there may be a click close button, but also trigger the click information flow event.
        NSMutableArray *array = [@[selfRenderView.iconImageView] mutableCopy];
        if (mediaView) {
            [array addObject:mediaView];
            [selfRenderView addSubview:mediaView];
                
            [mediaView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.right.bottom.equalTo(selfRenderView);
                make.top.equalTo(selfRenderView.mainImageView.mas_top);
            }];
        }
        [nativeADView registerClickableViewArray:array];

        // Bind a self-rendering view
        ATNativePrepareInfo *info = [ATNativePrepareInfo loadPrepareInfo:^(ATNativePrepareInfo * _Nonnull prepareInfo) {
            prepareInfo.textLabel = selfRenderView.textLabel;
            ......
        }];
        [nativeADView prepareWithNativePrepareInfo:info];

        // render and show ad
        [offer rendererWithConfiguration:config selfRenderView:selfRenderView nativeADView:nativeADView];
        [self.view addSubview:nativeADView];
    }
}

#pragma mark - delegate with loading
-(void) didFinishLoadingADWithPlacementID:(NSString *)placementID {
    NSLog(@"ATDrawListViewController:: didFinishLoadingADWithPlacementID:%@", placementID);
}

-(void) didFailToLoadADWithPlacementID:(NSString *)placementID error:(NSError *)error {
    NSLog(@"ATDrawListViewController:: didFailToLoadADWithPlacementID:%@ error:%@", placementID, error);
}

#pragma mark - delegate with native ad
-(void) didStartPlayingVideoInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra{
    NSLog(@"ATDrawListViewController:: didStartPlayingVideoInAdView:placementID:%@with extra: %@", placementID,extra);
}

-(void) didEndPlayingVideoInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra{
    NSLog(@"ATDrawListViewController:: didEndPlayingVideoInAdView:placementID:%@ extra: %@", placementID,extra);
}

-(void) didClickNativeAdInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra{
    NSLog(@"ATDrawListViewController:: didClickNativeAdInAdView:placementID:%@ with extra: %@", placementID,extra);
}

- (void) didDeepLinkOrJumpInAdView:(ATNativeADView *)adView placementID:(NSString *)placementID extra:(NSDictionary *)extra result:(BOOL)success {
    NSLog(@"ATDrawListViewController:: didDeepLinkOrJumpInAdView:placementID:%@ with extra: %@, success:%@", placementID,extra, success ? @"YES" : @"NO");
}

-(void) didShowNativeAdInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra{
    NSLog(@"ATDrawListViewController:: didShowNativeAdInAdView:placementID:%@ with extra: %@", placementID,extra);
}

-(void) didEnterFullScreenVideoInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra{
    NSLog(@"ATDrawListViewController:: didEnterFullScreenVideoInAdView:placementID:%@", placementID);
}

-(void) didExitFullScreenVideoInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra{
    NSLog(@"ATDrawListViewController:: didExitFullScreenVideoInAdView:placementID:%@", placementID);
}

-(void) didTapCloseButtonInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra {
    NSLog(@"ATDrawListViewController:: didTapCloseButtonInAdView:placementID:%@ extra:%@", placementID, extra);
}

- (void)didCloseDetailInAdView:(ATNativeADView *)adView placementID:(NSString *)placementID extra:(NSDictionary *)extra {
    NSLog(@"ATDrawListViewController:: didCloseDetailInAdView:placementID:%@ extra:%@", placementID, extra);
}

@end

Please refer to Demo's ATDrawListViewController class

Last modified: 2025-05-30Powered by