Menu

Template ads

1. Introduction

Template feed ads are relatively simple to use in native ads. Developers do not need to define the UI layout of internal ads. The SDK will provide a fully rendered View for developers to display at a designated location. The display example is as follows:

Fixed Location displayInformation flow list display
native_template_one_pic_thumbnative_template_list_pic_thumb

1.1 Integration suggestions

1. Load ads

    • To load ads through loadADWithPlacementID, please call the loading method in advance to request the ad. For example, you can preload the ad after opening the screen so that it can be displayed quickly when the ad needs to be triggered.
    • When calling the loaded API pass in the size you expect to make the AD platform fit, if the height is not limited to 0, the platform will return the size of the footage according to the width or its own rules.

2. Display ads

    • You can use getCurrentNativeAdRenderType in the ATNativeADView class to determine whether the advertisement is a template rendering type advertisement
    • Template ads will only return one View. Since it is the advertising platform that renders, the developer cannot layout the internal material.
    • Native ads can only be displayed in the same place at the same time. Otherwise, the first displayed Native ad will not be displayed or clicked normally.
    • According to the instructions for displaying ads below, complete the display logic of the ad. The main operations include:
      1. Get the ATNativeAdOffer material object;
      2. Generate the ATNativeADView container object;
      3. Render native Advertisement;
      4. Display the ATNativeADView container object.

3. Close ads

    • Remove the closed ATNativeADView view in the didTapCloseButtonInAdView callback

1.2 Notes

    • It is recommended to configure a preset strategy to improve the first cold The activated ad loading effect, for detailed instructions and access tutorials, see SDK preset strategy usage instructions
    • In order to facilitate the use of funnel reports to analyze advertising scenarios, it is recommended to call entryNativeScenarioWithPlacementID when you need to display native ads to record scenario statistics.
    • To ensure that ads can be obtained faster and at a higher price, it is recommended to obtain one ad at a time and perform the next ad load after acquisition. Please do not didFailToLoadADWithPlacementID method to execute ad loading in the callback, otherwise it will cause a lot of useless requests and may cause the application to freeze.

2 API Description

2.1 Loading ads

ATAdManager: Native advertising management class

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

Calling sample code

#import <AnyThinkNative/AnyThinkNative.h>

- (void)loadAd {
    CGSize size = CGSizeMake(UIScreen.mainScreen.bounds.size.width, 350);
    NSDictionary *extra = @{
    /*
     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.
        */
        kATExtraInfoNativeAdSizeKey:[NSValue valueWithCGSize:size],
        // Whether to enable adaptive height. This parameter is disabled by default. 
        // If this parameter is set to yes, this parameter is enabled
        kATNativeAdSizeToFitKey:@YES,
    };
    [[ATAdManager sharedManager] loadADWithPlacementID:@"your Native placement id" extra:extra delegate:self];
}

2.2 Display Advertising

Note:

    • When the ad slot is configured with a template rendering type ad, the width and height of the ad must be passed before making a request.
    • Template ads have their own width-to-height ratio, which can be viewed in the backend of the advertising platform. Try to choose a template with the same or close width-to-height ratio in the background of the advertising platform, and use that width-to-height ratio to load and display ads in the code to obtain the best display effect.
    • The width and height of ATNativeAdView must be consistent with the width and height corresponding to kATExtraInfoNativeAdSizeKey, otherwise the display may be incomplete or too small.
MethodDescription
getNativeAdOfferWithPlacementID:Get Native information flow advertising view
placementId: TopOn's advertising slot id
getNativeAdOfferWithPlacementID: scene:Get the native information flow advertising view
placementId: TopOn's advertising slot id
scene: scene id, no space can be passed @""
nativeAdReadyForPlacementID:Determine whether there is currently an ad that can be displayed
placementId: TopOn's advertising slot id

ATNativeADView The object of the native advertising view, the attribute description is as follows:

Attribute or methodDescription
initWithConfiguration: currentOffer: placementIDInitialize NativeADView object
configuration: NativeADView configured object
currentOffer: obtained ATNativeAdOffer object
placementID: advertising slot id
networkFirmIDThe ID corresponding to the current advertising platform, used to distinguish advertising platforms, refer to Network Firm Id Table
getNativeAdTypeGet the ad type
ATNativeAdTypeFeed: information flow ad (native ad)
ATNativeAdTypePaster: pre-roll ad
getCurrentNativeAdRenderTypeGet the ad rendering type
ATNativeAdRenderSelfRender: self-rendering ads
ATNativeAdRenderExpress: template ads
initWithConfigurationInitialize the configuration object of NativeADView

ATNativeAdOffer The object of native advertising management material. The attribute description is as follows:

Attribute or methodDescription
networkFirmIDCurrent ad The ID corresponding to the platform is used to distinguish the advertising platform, refer to Network Firm Id Table
adOfferInfoGet the ad cache information with the highest priority for the current ad slot, which mainly includes the id information of the third-party aggregation platform Callback information description
rendererWithConfiguration: selfRenderView: nativeADView:Call this method before displaying the ad to render the native ad container view
configuration: ATNativeADView Configuration object
selfRenderView: pass nil
nativeADView: ATNativeADView object

Sample code for calling

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

CGFloat adViewWidth = offer.nativeAd.nativeExpressAdViewWidth;
CGFloat adViewHeight = offer.nativeAd.nativeExpressAdViewHeight;
// Because some platform template advertising width and height may return 0, 
// it is necessary to be compatible with the bottom processing, it is recommended to set the size width and height passed by load.
if (adViewWidth == 0) {
    adViewWidth = UIScreen.mainScreen.bounds.size.width;
}
if (adViewHeight == 0) {
    adViewHeight = 350;
}
CGRect adFrame = CGRectMake(.0f, 64.0f, adViewWidth, adViewHeight);
ATNativeADConfiguration *config = [[ATNativeADConfiguration alloc] init];
// Set the AD view rendered by ATNativeADView by the size of the AD material.
config.ADFrame = adFrame;
config.delegate = self;
config.rootViewController = self;

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

// renderer and show ads
[offer rendererWithConfiguration:config selfRenderView:nil nativeADView:nativeADView];
[self.view addSubview:nativeADView];

2.3 Scene statistics

MethodDescription
entryNativeScenarioWithPlacementID:scene:The corresponding advertising slot enters the business scene cache status statistics placementId: Advertising slot Id scene: Ad display scene, scene parameters can be created from the background, if there is no, empty @ can be passed "" For usage, please refer to scenario statistics
/* 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 sharedInstance] entryNativeScenarioWithPlacementID:@"your Native placement id"" scene:@"your scenarioID"];

// Check to see if the AD is ready before showing
if ([[ATAdManager sharedManager] nativeAdReadyForPlacementID:@"your Native placementID"]) {
    ATNativeAdOffer *offer = [[ATAdManager sharedManager] getNativeAdOfferWithPlacementID:@"your Native placementID" scene:@"your scenarioID"];
}

2.4 Closed the ad

In the triggering close callback protocol, we need to close the Removal of native information feed ads

-(void) didTapCloseButtonInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra {
    NSLog(@"ATNativeViewController:: didTapCloseButtonInAdView:placementID:%@ extra:%@", placementID, extra);
    [self.adView removeFromSuperview];
    self.adView = nil;
}

2.5 Delegate callback

ATAdLoadingDelegate delegate method

MethodDescription
didFinishLoadingADWithPlacementID:corresponds toAdvertising slot ad Loading success callback
placementId: Advertising slot Id
didFailToLoadADWithPlacementID: error:corresponds to advertising slot adsLoading failure callback
placementId: Advertising slot Id
error: Ad loading failure information

ATNativeADDelegate delegate method

MethodDescription
didShowNativeAdInAdView: placementID: extra: Native ad display 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 full-screen video advertising
didExitFullScreenVideoInAdView: placementID: extra:Native exit full-screen video advertising
didTapCloseButtonInAdView : placementID: extra:Close button in Native ads Click
didLoadSuccessDrawWith: placementID: extra:Native draw ad loaded successfully
didDeepLinkOrJumpInAdView: placementID: extra: result:Native ad click jump is in Deeplink form. Currently, it is only returned for TopOn Adx ads
Native ad click to close the details page
extra: Extended parameter reference Documentation

Call sample code

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

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

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

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

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

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

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

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

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

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

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

2.6 Other APIs

MethodDescription
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); didCloseDetailInAdView: placementID: extra:

3. Sample code

#import "ATNativeExpressViewController.h"

@interface ATNativeExpressViewController()<ATNativeADDelegate>

@property(nonatomic) ATNativeADView *adView;

@end

@implementation ATNativeExpressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadAd];
}

- (void)loadAd {
    CGSize size = CGSizeMake(UIScreen.mainScreen.bounds.size.width, 350);
    NSDictionary *extra = @{ 
    /* 
	    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. 
    */ 
	    kATExtraInfoNativeAdSizeKey:[NSValue valueWithCGSize:size], 
	    // Whether to enable adaptive height. This parameter is disabled by default. 
	    // If this parameter is set to yes, this parameter is enabled 
	    kATNativeAdSizeToFitKey:@YES,
     }; 
    [[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"]) {
        ATNativeAdOffer *offer = [[ATAdManager sharedManager] getNativeAdOfferWithPlacementID:@"your Native placement id" scene:@"your scenarioID"];

        CGFloat adViewWidth = offer.nativeAd.nativeExpressAdViewWidth;
        CGFloat adViewHeight = offer.nativeAd.nativeExpressAdViewHeight;
     // Because some platform template advertising width and height may return 0,  
     // it is necessary to be compatible with the bottom processing, it is recommended to set the size width and height passed by load.
        if (adViewWidth == 0) {
            adViewWidth = UIScreen.mainScreen.bounds.size.width;
        }
        if (adViewHeight == 0) {
            adViewHeight = 350;
        }
        CGRect adFrame = CGRectMake(.0f, 64.0f, adViewWidth, adViewHeight);
        ATNativeADConfiguration *config = [[ATNativeADConfiguration alloc] init];
         // Set the AD view rendered by ATNativeADView by the size of the AD material.
        config.ADFrame = adFrame;
        config.delegate = self;
        config.rootViewController = self;
        
        ATNativeADView *nativeADView = [[ATNativeADView alloc] initWithConfiguration:config currentOffer:offer placementID:@"your Native placement id"];
        self.adView = nativeADView;
        
         [offer rendererWithConfiguration:config selfRenderView:nil nativeADView:nativeADView];
         [self.view addSubview:nativeADView];
    }
}

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

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

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

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

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

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

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

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

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

-(void) didTapCloseButtonInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra {
    NSLog(@"ATNativeViewController:: didTapCloseButtonInAdView:placementID:%@ extra:%@", placementID, extra);
    [self.adView removeFromSuperview];
    self.adView = nil;
}

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

@end

Please refer to Demo's ATNativeExpressViewController class

Last modified: 2025-05-30Powered by