Menu

Banner Ads

1. Integration Recommendations

1.1 Width and Height Settings

  • The width and height settings need to be consistent with the aspect ratio configured in the Taku backend and adjusted according to actual effects.

1.2 Auto Refresh

  • Auto refresh is not enabled by default. You can configure the refresh time to enable or disable refresh in the advanced settings of the ad placement in the Taku backend.
  • The Banner ad View must be added to the window and be visible to trigger auto refresh.
  • If the ad platform provides auto refresh functionality, it is recommended to disable the ad platform's auto refresh and only use the auto refresh provided by Taku to avoid unpredictable issues caused by conflicts.
  • After enabling the auto refresh feature, add ATBannerView to the layout and ensure it is in a visible state, then call the loadADWithPlacementID: method once. Subsequent displays and refreshes will be automatically executed by the SDK.

1.4 Sample Code

  • For detailed sample code, please refer to: BannerVC.m in Demo

1.5 ⚠️ Version Update Notes

Version V6.4.39 and above (including V6.4.39) supports passing in a controller object when loading ads to adapt to the requirement of some ad platforms that the loading controller and display controller must match. If you cannot adapt to passing in a controller object for some reasons, it may cause the problem of invalid clicks after these ad platforms are displayed. If you need to adapt, please use the following APIs together and pass in the same controller object:

objc Copy
/// Load banner ad
/// @param placementID Ad placement ID
/// @param extra Extra parameters
/// @param viewController Target controller, for example, the popup window after Banner click will use this controller, you need to reference it, SDK internally uses weak reference
/// @param delegate Delegate object
- (void)loadADWithPlacementID:(NSString *)placementID
                        extra:(NSDictionary *)extra
               viewController:(UIViewController *)viewController
                     delegate:(id<ATAdLoadingDelegate>)delegate;

/// Check if banner ad is ready
/// @param placementID Ad placement ID
/// @param showViewController Pass in the same object as the controller in the loading method -[ATAdManager loadADWithPlacementID:extra:viewController:delegate:]
- (BOOL)bannerAdReadyForPlacementID:(NSString *)placementID showViewController:(UIViewController *)showViewController;

/// Get BannerView object for display
/// @param placementID Ad placement ID
/// @param ATShowConfig config Configuration object, if viewController was passed in loadADWithPlacementID, then the same object needs to be passed here
/// @param nativeMixBannerViewBlock For custom banner ads, returns components for custom layout
- (nullable ATBannerView *)retrieveBannerViewForPlacementID:(NSString *)placementID
                                                     config:(ATShowConfig *)config
                                     nativeMixBannerViewBlock:(nullable NativeMixBannerViewBlock)nativeMixBannerViewBlock;

Banner ads on different platforms have certain rule restrictions:

  1. Proportional scaling rule: For example, if the banner ad size configured in the backend is 640*100, to fill the screen width, calculate height H = (screen width * 100)/640; then the filled size is: CGSizeMake(screen width, H);
  2. Fixed size rule: Select a fixed size in the backend configuration, and also set the same fixed size in the code
  3. Adaptive rule: Only supported by some ad platforms, and you need to select a non-fixed size style in the backend. For code details, see the method example in Demo - [AdLoadConfigTool banner_loadExtraConfigAppendAdmob:loadConfigDict]
  • The extra dictionary in this step supports passing in relevant parameters for configuring ads and your custom parameters. You can view more information about extra parameters here.
objc Copy
//Import header file
#import <AnyThinkBanner/AnyThinkBanner.h>

@interface BannerVC () <ATBannerDelegate>

@property (nonatomic, strong) ATBannerView *bannerView;
@property (nonatomic, assign) BOOL hasLoaded; // Ad loading status identifier

@end

@implementation BannerVC

//Ad placement ID
#define BannerPlacementID @"b680a1e7874fce"

//Scene ID, optional, can be generated in the backend. If not available, pass an empty string
#define BannerSceneID @""

//Please note that banner size needs to be consistent with the ratio configured in the backend
#define BannerSize CGSizeMake(320, 50)

#pragma mark - Load Ad
/// Load ad
- (void)loadAd {
 
    [self showLog:kLocalizeStr(@"Clicked load ad")];
      
    NSMutableDictionary * loadConfigDict = [NSMutableDictionary dictionary];
    
    /*
     Note that banner ads on different platforms have certain restrictions. For example, the configured banner ad is 640*100. In order to fill the screen width, the height H = (screen width *100)/640 is calculated. Then the extra size of the load is (screen width: H).
     
     Note that banner ads on different platforms have certain restrictions. For example, the configured banner AD is 640*100. In order to fill the screen width, the height H = (screen width *100)/640 is calculated. Then the extra size of the load is (screen width: H).
     */
    [loadConfigDict setValue:[NSValue valueWithCGSize:BannerSize] forKey:kATAdLoadingExtraBannerAdSizeKey];
    
    //Set custom parameters
    [loadConfigDict setValue:@"media_val_BannerVC" forKey:kATAdLoadingExtraMediaExtraKey];
 
    //Start loading
    [[ATAdManager sharedManager] loadADWithPlacementID:BannerPlacementID extra:loadConfigDict delegate:self];
}

#pragma mark - Ad placement delegate callbacks
/// Ad placement loading completed
/// - Parameter placementID: Ad placement ID
- (void)didFinishLoadingADWithPlacementID:(NSString *)placementID {
     self.hasLoaded = YES;
 }
 
/// Ad placement loading failed
/// - Parameters:
///   - placementID: Ad placement ID
///   - error: Error information
- (void)didFailToLoadADWithPlacementID:(NSString *)placementID error:(NSError *)error { 
     self.hasLoaded = NO;
}

Statistics scene arrival rate, displayed in the backend's Data Reports -> Funnel Analysis Report -> Arrival at Ad Scene, called before showing ads.

objc Copy
#pragma mark - Show Ad
/// Show ad
- (void)showAd {
    
    //Scene statistics function, displayed in the backend's Data Reports -> Funnel Analysis Report -> Arrival at Ad Scene, called before showing ads. Optional integration
    [[ATAdManager sharedManager] entryBannerScenarioWithPlacementID:BannerPlacementID scene:BannerSceneID];

    //Check if ready
    if (![[ATAdManager sharedManager] bannerAdReadyForPlacementID:BannerPlacementID]) {
        [self loadAd];
        return;
    }
    
    //Show configuration, Scene passes in the backend scene ID, if not available pass an empty string, showCustomExt parameter can pass in custom parameter string
    ATShowConfig *config = [[ATShowConfig alloc] initWithScene:BannerSceneID showCustomExt:@"testShowCustomExt"];
 
    //Show ad
    ATBannerView *bannerView = [[ATAdManager sharedManager] retrieveBannerViewForPlacementID:BannerPlacementID config:config];
    if (bannerView != nil) {
        //Assignment
        bannerView.delegate = self;
        bannerView.presentingViewController = self;
        bannerView.translatesAutoresizingMaskIntoConstraints = NO;
        [self.view addSubview:bannerView];
        self.bannerView = bannerView;
        
        //Layout
        [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.view);
            make.height.equalTo(@(BannerSize.height));
            make.width.equalTo(@(BannerSize.width));
            make.top.equalTo(self.textView.mas_bottom).offset(5);
        }];
    }
}

/// Get display revenue
/// - Parameters:
///   - placementID: Ad placement ID
///   - extra: Extra information dictionary
- (void)didRevenueForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra { 
}
 
/// Close button clicked (when user clicks the close button on the banner)
/// - Parameters:
///   - bannerView: Banner ad view object
///   - placementID: Ad placement ID
///   - extra: Extra information dictionary
- (void)bannerView:(ATBannerView *)bannerView didTapCloseButtonWithPlacementID:(NSString *)placementID extra:(NSDictionary *)extra { 
    // Received close button click callback, remove bannerView
    [self removeAd];
}

/// Banner ad has been shown
/// - Parameters:
///   - bannerView: Banner ad view object
///   - placementID: Ad placement ID
///   - extra: Extra information dictionary
- (void)bannerView:(ATBannerView *)bannerView didShowAdWithPlacementID:(NSString *)placementID extra:(NSDictionary *)extra { 
}

/// Banner ad was clicked
/// - Parameters:
///   - bannerView: Banner ad view object
///   - placementID: Ad placement ID
///   - extra: Extra information dictionary
- (void)bannerView:(ATBannerView *)bannerView didClickWithPlacementID:(NSString *)placementID extra:(NSDictionary *)extra{ 
}

/// Banner ad has auto refreshed
/// - Parameters:
///   - bannerView: Banner ad view object
///   - placementID: Ad placement ID
///   - extra: Extra information dictionary
- (void)bannerView:(ATBannerView *)bannerView didAutoRefreshWithPlacement:(NSString *)placementID extra:(NSDictionary *)extra { 
}

/// Banner ad auto refresh failed
/// - Parameters:
///   - bannerView: Banner ad view object
///   - placementID: Ad placement ID
///   - error: Error information
- (void)bannerView:(ATBannerView *)bannerView failedToAutoRefreshWithPlacementID:(NSString *)placementID error:(NSError *)error { 
}
 
/// Banner ad has opened or jumped to deep link page
/// - Parameters:
///   - bannerView: Banner ad view object
///   - placementID: Ad placement ID
///   - extra: Extra information
///   - success: Whether successful
- (void)bannerView:(ATBannerView *)bannerView didDeepLinkOrJumpForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra result:(BOOL)success { 
}
objc Copy
#pragma mark - Destroy Ad
- (void)removeAd { 
    [self.bannerView destroyBanner];
    [self.bannerView removeFromSuperview];
    self.bannerView = nil;
    self.hasLoaded = NO;
}
Previous
Custom Splash Ads
Next
Custom Banner Ads
Last modified: 2025-07-28Powered by