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 display | Information flow list display |
---|---|
![]() | ![]() |
1. Load ads
2. Display ads
3. Close ads
ATAdManager: Native advertising management class
Method | Description |
---|---|
sharedManager | Get 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];
}
Note:
Method | Description |
---|---|
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 method | Description |
---|---|
initWithConfiguration: currentOffer: placementID | Initialize NativeADView object configuration: NativeADView configured object currentOffer: obtained ATNativeAdOffer object placementID: advertising slot id |
networkFirmID | The ID corresponding to the current advertising platform, used to distinguish advertising platforms, refer to Network Firm Id Table |
getNativeAdType | Get the ad type ATNativeAdTypeFeed: information flow ad (native ad) ATNativeAdTypePaster: pre-roll ad |
getCurrentNativeAdRenderType | Get the ad rendering type ATNativeAdRenderSelfRender: self-rendering ads ATNativeAdRenderExpress: template ads |
initWithConfiguration | Initialize the configuration object of NativeADView |
ATNativeAdOffer The object of native advertising management material. The attribute description is as follows:
Attribute or method | Description |
---|---|
networkFirmID | Current ad The ID corresponding to the platform is used to distinguish the advertising platform, refer to Network Firm Id Table |
adOfferInfo | Get 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];
Method | Description |
---|---|
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"];
}
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;
}
ATAdLoadingDelegate delegate method
Method | Description |
---|---|
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
Method | Description |
---|---|
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);
}
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); didCloseDetailInAdView: placementID: extra:
#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