Banner ads provide ads in the form of View, at the bottom or top of the content Small bar ads displayed.
1. Load ads
2. Display ads
3. Ad preloading
4. Preset strategy
ATAdManager: Banner ad management class
Method | Description |
---|---|
sharedManager | Get ATAdManager singleton object |
loadADWithPlacementID: extra: delegate: | Interstitial loading method placementId: TopOn's advertising slot id extra: local configuration parameters delegate: delegate object |
Issues that need attention when loading:
Call code example
#import <AnyThinkBanner/AnyThinkBanner.h>
- (void)loadBannerAdView {
// Here, the aspect ratio 320*50 equal scale scaling is used as an example
CGSize size = CGSizeMake([UIScreen mainScreen].bounds.size.width, ([UIScreen mainScreen].bounds.size.width * 50) / 320);
NSDictionary *extra = @{ kATAdLoadingExtraBannerAdSizeKey : [NSValue valueWithCGSize:size], };
[[ATAdManager sharedManager] loadADWithPlacementID:@"your banner placementID" extra:extra delegate:self];
}
For Admob platform supports Admob banner ad adaptation. First, the Admob SDK header file is introduced:
#import <GoogleMobileAds/GoogleMobileAds.h>
Then get the Admob banner adaptive GADAdSize, then pass in extra kATAdLoadingExtraAdmobBannerSizeKey and kATAdLoadingExtraAdmobAdSizeFlagsKey Just set it up. An example is as follows:
//GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth self-adaptation
//GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth Portrait screen
//GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth landscape
// The example is a full screen width
GADAdSize admobSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(CGRectGetWidth(self.view.bounds));
[[ATAdManager sharedManager] loadADWithPlacementID:@"your banner placementID"
extra:@{kATAdLoadingExtraBannerAdSizeKey:[NSValue valueWithCGSize:CGSizeMake(CGRectGetWidth(self.view.bounds), 250.0f)],
kATAdLoadingExtraAdmobBannerSizeKey:[NSValue valueWithCGSize:admobSize.size],
kATAdLoadingExtraAdmobAdSizeFlagsKey:@(admobSize.flags)} delegate:self];
Method | Description |
---|---|
retrieveBannerViewForPlacementID: | Get banner ad view placementId: TopOn's advertising slot id |
retrieveBannerViewForPlacementID: scene: | Get the banner ad view placementId: TopOn's ad slot id scene: scene id, no space can be passed @"" |
bannerAdReadyForPlacementID: | Determine whether there are currently ads that can be displayed placementId: TopOn's advertising slot id |
Call the sample code
-(void) showBanner {
// Check to see if the AD is ready before showing
if ([[ATAdManager sharedManager] bannerAdReadyForPlacementID:@"your banner placementID"]) {
// Remove any old Bannerviews that may exist
NSInteger tag = 3333;
[[self.view viewWithTag:tag] removeFromSuperview];
//Retrieve banner view
ATBannerView *bannerView = [[ATAdManager sharedManager] retrieveBannerViewForPlacementID:@"your banner placementID"];
if (bannerView != nil) {
bannerView.delegate = self;
bannerView.presentingViewController = self;
bannerView.translatesAutoresizingMaskIntoConstraints = NO;
bannerView.tag = tag;
[self.view addSubview:bannerView];
//Layour 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");
}
}
If the banner AD space is configured to use native self-rendered ads as banners, please refer to the following code to integrate:
Note: Please select native banner ads for Meta(Facebook) platform ads.
-(void) showBanner {
// Determine if the AD is ready before showing it
if ([[ATAdManager sharedManager] bannerAdReadyForPlacementID:@"your banner placementID"]) {
// Remove any old Bannerviews that may exist
NSInteger tag = 3333;
[[self.view viewWithTag:tag] removeFromSuperview];
//Retrieve banner view
ATShowConfig *showConfig = ATShowConfig.new;
showConfig.scene = @"your scene id";
showConfig.showCustomExt = @"testShowCustomExt";
__weak __typeof(self)weakSelf = self;
ATBannerView *bannerView = [[ATAdManager sharedManager] retrieveBannerViewForPlacementID:@"your banner ad id"
config:showConfig
nativeMixBannerViewBlock:^(ATNativeBannerView * _Nonnull nativeBannerView) {
// Constraining the positions of controls in ATNativeBannerView
[weakSelf developerSlefRender:nativeBannerView];
}];
if (bannerView != nil) {
bannerView.delegate = self;
bannerView.presentingViewController = self;
bannerView.translatesAutoresizingMaskIntoConstraints = NO;
bannerView.tag = tag;
[self.view addSubview:bannerView];
//Layour 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 {
[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);
}];
NSMutableArray *regisArray = [NSMutableArray array];
if (nativeBannerView.textLabel) {
[regisArray addObject:nativeBannerView.textLabel];
}
if (nativeBannerView.titleLabel) {
[regisArray addObject:nativeBannerView.titleLabel];
}
[nativeBannerView registerClickableViewArray:regisArray];
}
Statistics on the probability of users reaching the scene, and present the data report in the background-> Funnel analysis report-> reaches the advertising scene, so it is recommended that developers call it in the right place.
Method | Description |
---|---|
entryBannerScenarioWithPlacementID: 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, please refer to Business scenario cache status statistics |
Scenario statistics call example:
/* 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] entryBannerScenarioWithPlacementID:@"your banner placement id" scene:@"your scenarioID"];
if ([[ATAdManager sharedManager] bannerAdReadyForPlacementID:@"your banner placement id"]) {
ATBannerView *bannerView = [[ATAdManager sharedManager] retrieveBannerViewForPlacementID:@"your banner placement id" scene:@"your scenarioID"];
}
If necessary, use the following code to remove Banner from the screen:
[self.bannerView removeFromSuperview];
self.bannerView = nil;
If you only want to temporarily hide the Banner (rather than remove it from the screen), the simulation scenario is that interface A is transferred to interface B, at this time you need to hide the banner AD of interface A, and then switch back to interface A to display the banner AD. Please use the code here:
self.bannerView.hidden = YES;
After hiding the Banner, You can redisplay it using the following code:
self.bannerView.hidden = NO;
ATAdLoadingDelegate delegate method
Method | Description |
---|---|
didFinishLoadingADWithPlacementID: | corresponds to advertising slot id Loading success callback placementId: Advertisement slot Id |
didFailToLoadADWithPlacementID: error: | Corresponding to advertising slot id loading failure callback placementId: advertising slot Id error: advertising loading failure information |
didStartLoadingADSourceWithPlacementID: extra : | corresponds to A callback for an advertising source in the advertising slot id to start loading ads placementId: advertising slot Id extra: additional advertising parameters |
didFinishLoadingADSourceWithPlacementID: extra: | Corresponding to An advertising source in the advertising slot id successfully loads the advertisement Callback placementId: Advertising slot Id extra: Advertising additional parameters |
didFailToLoadADSourceWithPlacementID: extra: error: | corresponds toa certain advertising source in the advertising slot id callback for failure to load ads placementId: advertising slot Id extra : Advertising additional parameters error: Ad loading failure information |
didStartBiddingADSourceWithPlacementID: extra: | corresponds to An advertising source in the advertising slot id Callback for the start of bidding for ads placementId: Advertising slot Id extra: Advertising additional parameters |
didFinishBiddingADSourceWithPlacementID: extra: | corresponds to An advertising source in the advertising slot id Callback for successful advertising bidding placementId: Advertising slot Id extra: Advertising additional parameters |
didFailBiddingADSourceWithPlacementID: extra: error: | Corresponds to a certain advertising source in the advertising slot id Callback for bidding failure of bidding ads placementId: Advertising slot Id extra: Advertising additional parameters error: Bidding advertising failure information |
ATBannerDelegate delegate method
Method | Description |
---|---|
bannerView:failedToAutoRefreshWithPlacementID: error: | bannerView automatic refresh failed |
bannerView:didShowAdWithPlacementID:extra: | bannerView displays results |
bannerView:didClickWithPlacementID:extra : | bannerView click |
bannerView:didCloseWithPlacementID:extra: | bannerView closed |
bannerView:didAutoRefreshWithPlacement:extra: | bannerView automatically refreshes |
bannerView:didTapCloseButtonWithPlacementID: extra: | bannerView clicks the close button |
bannerView:didDeepLinkOrJumpForPlacementID: extra:result: | Whether the bannerView click jump is in Deeplink form, currently only for TopOn Adx's advertising return |
extra:Extended parameter reference Documentation |
Call code example
#pragma mark - loading delegate methods
- (void)didStartLoadingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary*)extra {
NSLog(@"ADSource--AD--Start--ATBannerViewController::didStartLoadingADSourceWithPlacementID:%@---extra:%@", placementID,extra);
}
- (void)didFinishLoadingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary*)extra {
NSLog(@"ADSource--AD--Finish--ATBannerViewController::didFinishLoadingADSourceWithPlacementID:%@---extra:%@", placementID,extra);
}
- (void)didFailToLoadADSourceWithPlacementID:(NSString*)placementID extra:(NSDictionary*)extra error:(NSError*)error {
NSLog(@"ADSource--AD--Fail--ATBannerViewController::didFailToLoadADSourceWithPlacementID:%@---error:%@", placementID,error);
}
// bidding
- (void)didStartBiddingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary*)extra {
NSLog(@"ADSource--bid--Start--ATBannerViewController::didStartBiddingADSourceWithPlacementID:%@---extra:%@", placementID,extra);
}
- (void)didFinishBiddingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary*)extra {
NSLog(@"ADSource--bid--Finish--ATBannerViewController::didFinishBiddingADSourceWithPlacementID:%@--extra:%@", placementID,extra);
}
- (void)didFailBiddingADSourceWithPlacementID:(NSString*)placementID extra:(NSDictionary*)extra error:(NSError*)error {
NSLog(@"ADSource--bid--Fail--ATBannerViewController::didFailBiddingADSourceWithPlacementID:%@--error:%@", placementID,error);
}
- (void) didFinishLoadingADWithPlacementID:(NSString *)placementID {
NSLog(@"ATBannerViewController::didFinishLoadingADWithPlacementID:%@", placementID);
}
-(void) didFailToLoadADWithPlacementID:(NSString*)placementID error:(NSError*)error {
NSLog(@"ATBannerViewController::didFailToLoadADWithPlacementID:%@ error:%@", placementID, error);
}
#pragma mark - banner delegate
- (void)bannerView:(ATBannerView*)bannerView didShowAdWithPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {
NSLog(@"ATBannerViewController::bannerView:didShowAdWithPlacementID:%@ with extra: %@", placementID,extra);
}
- (void)bannerView:(ATBannerView*)bannerView didClickWithPlacementID:(NSString*)placementID extra:(NSDictionary *)extra{
NSLog(@"ATBannerViewController::bannerView:didClickWithPlacementID:%@ with extra: %@", placementID,extra);
}
- (void)bannerView:(ATBannerView*)bannerView didAutoRefreshWithPlacement:(NSString*)placementID extra:(NSDictionary *)extra {
NSLog(@"ATBannerViewController::bannerView:didAutoRefreshWithPlacement:%@ with extra: %@", placementID,extra);
}
- (void) bannerView:(ATBannerView *)bannerView failedToAutoRefreshWithPlacementID:(NSString *)placementID error:(NSError *)error {
NSLog(@"ATBannerViewController::bannerView:failedToAutoRefreshWithPlacementID:%@ error:%@", placementID, error);
}
- (void)bannerView:(ATBannerView*)bannerView didTapCloseButtonWithPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
NSLog(@"ATBannerViewController::bannerView:didTapCloseButtonWithPlacementID:%@ extra: %@", placementID,extra);
// After receiving the Close button callback, you need to remove bannerView yourself
}
- (void)bannerView:(ATBannerView *)bannerView didDeepLinkOrJumpForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra result:(BOOL)success {
NSLog(@"ATBannerViewController:: didDeepLinkOrJumpForPlacementID:placementID:%@ with extra: %@, success:%@", placementID,extra, success ? @"YES" : @"NO");
}
Method | Description |
---|---|
getBannerValidAdsForPlacementID: | Query the ad slot All cached information, the first item in the array is the advertising data to be displayed. placementId: the advertising slot Id to be queried |
NSArray *array = [[ATAdManager sharedManager] getBannerValidAdsForPlacementID:@"your banner placementID"];
NSLog(@"ValidAds.count:%ld--- ValidAds:%@",array.count,array);
#import <AnyThinkBanner/AnyThinkBanner.h>
@interface ATBannerViewController () <ATAdLoadingDelegate, ATBannerDelegate>
@end
@implementation ATBannerViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self loadBannerAdView];
}
- (void)loadBannerAdView {
// Here, the aspect ratio 320*50 equal scale scaling is used as an example
CGSize size = CGSizeMake([UIScreen mainScreen].bounds.size.width, ([UIScreen mainScreen].bounds.size.width * 50) / 320);
NSDictionary *extra = @{ kATAdLoadingExtraBannerAdSizeKey : [NSValue valueWithCGSize:size], };
[[ATAdManager sharedManager] loadADWithPlacementID:@"your banner placementID" 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] entryBannerScenarioWithPlacementID:@"your banner placement id" scene:@"your scenarioID"];
}
- (void)showBanner {
[self entryAdScenario];
// Check to see if the AD is ready before showing
if ([[ATAdManager sharedManager] bannerAdReadyForPlacementID:@"your banner placementID"]) {
NSInteger tag = 3333;
[[self.view viewWithTag:tag] removeFromSuperview];
//Retrieve banner view
ATBannerView *bannerView = [[ATAdManager sharedManager] retrieveBannerViewForPlacementID:@"your banner placementID" scene:@"your scenarioID"];
bannerView.delegate = self;
bannerView.presentingViewController = self;
bannerView.translatesAutoresizingMaskIntoConstraints = NO;
bannerView.tag = tag;
[self.view addSubview:bannerView];
//Layour 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");
}
}
#pragma mark - loading delegate method(s)
- (void)didStartLoadingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary*)extra {
NSLog(@"ADSource--AD--Start--ATBannerViewController::didStartLoadingADSourceWithPlacementID:%@---extra:%@", placementID,extra);
}
- (void)didFinishLoadingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary*)extra {
NSLog(@"ADSource--AD--Finish--ATBannerViewController::didFinishLoadingADSourceWithPlacementID:%@---extra:%@", placementID,extra);
}
- (void)didFailToLoadADSourceWithPlacementID:(NSString*)placementID extra:(NSDictionary*)extra error:(NSError*)error {
NSLog(@"ADSource--AD--Fail--ATBannerViewController::didFailToLoadADSourceWithPlacementID:%@---error:%@", placementID,error);
}
// bidding
- (void)didStartBiddingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary*)extra {
NSLog(@"ADSource--bid--Start--ATBannerViewController::didStartBiddingADSourceWithPlacementID:%@---extra:%@", placementID,extra);
}
- (void)didFinishBiddingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary*)extra {
NSLog(@"ADSource--bid--Finish--ATBannerViewController::didFinishBiddingADSourceWithPlacementID:%@--extra:%@", placementID,extra);
}
- (void)didFailBiddingADSourceWithPlacementID:(NSString*)placementID extra:(NSDictionary*)extra error:(NSError*)error {
NSLog(@"ADSource--bid--Fail--ATBannerViewController::didFailBiddingADSourceWithPlacementID:%@--error:%@", placementID,error);
}
- (void) didFinishLoadingADWithPlacementID:(NSString *)placementID {
NSLog(@"ATBannerViewController::didFinishLoadingADWithPlacementID:%@", placementID);
}
-(void) didFailToLoadADWithPlacementID:(NSString*)placementID error:(NSError*)error {
NSLog(@"ATBannerViewController::didFailToLoadADWithPlacementID:%@ error:%@", placementID, error);
}
#pragma mark - banner delegate
- (void)bannerView:(ATBannerView*)bannerView didShowAdWithPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {
NSLog(@"ATBannerViewController::bannerView:didShowAdWithPlacementID:%@ with extra: %@", placementID,extra);
}
- (void)bannerView:(ATBannerView*)bannerView didClickWithPlacementID:(NSString*)placementID extra:(NSDictionary *)extra{
NSLog(@"ATBannerViewController::bannerView:didClickWithPlacementID:%@ with extra: %@", placementID,extra);
}
- (void)bannerView:(ATBannerView*)bannerView didAutoRefreshWithPlacement:(NSString*)placementID extra:(NSDictionary *)extra {
NSLog(@"ATBannerViewController::bannerView:didAutoRefreshWithPlacement:%@ with extra: %@", placementID,extra);
}
- (void) bannerView:(ATBannerView *)bannerView failedToAutoRefreshWithPlacementID:(NSString *)placementID error:(NSError *)error {
NSLog(@"ATBannerViewController::bannerView:failedToAutoRefreshWithPlacementID:%@ error:%@", placementID, error);
}
- (void)bannerView:(ATBannerView*)bannerView didTapCloseButtonWithPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
NSLog(@"ATBannerViewController::bannerView:didTapCloseButtonWithPlacementID:%@ extra: %@", placementID,extra);
// After receiving the Close button callback, you need to remove bannerView yourself
}
- (void)bannerView:(ATBannerView *)bannerView didDeepLinkOrJumpForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra result:(BOOL)success {
NSLog(@"ATBannerViewController:: didDeepLinkOrJumpForPlacementID:placementID:%@ with extra: %@, success:%@", placementID,extra, success ? @"YES" : @"NO");
}
@end
Please refer to Demo's ATBannerViewController class