Menu

Custom Banner Ad Adapter

πŸ’‘Tips: The class name can be customized, but it must be consistent with the custom ad platform class name configured in the backend. For example, if the adapter class name added in the backend is: DemoCustomBannerAdapter, you need to create the corresponding DemoCustomBannerAdapter.m file.

Copy
Banner/
β”œβ”€β”€ DemoCustomBannerAdapter.h          # Banner ad adapter header file
β”œβ”€β”€ DemoCustomBannerAdapter.m          # Banner ad adapter implementation file
β”œβ”€β”€ DemoCustomBannerDelegate.h         # Banner ad delegate header file
└── DemoCustomBannerDelegate.m         # Banner ad delegate implementation file

2. Required Methods to Override

  • You need to inherit from DemoCustomBaseAdapter and override the relevant methods:
  • When developers call the ad loading API, the custom Adapter's loadADWithArgument: method will be called
Method Parameter Description Purpose
- (void)loadADWithArgument:(ATAdMediationArgument *)argument argument: Contains parameters from server and local configuration Used to get server and local configuration parameters, implement custom ad loading logic

3. Callback Method Description

Banner ad adapters support the following callback methods, which inherit from the ATBaseTrackProtocol and ATBannerTrackProtocol protocols:

3.1 Basic Ad Event Callbacks

Method Description
- (void)atOnAdMetaLoadFinish:(NSDictionary *)adExtra Callback to developer when ad data loading is complete
- (void)atOnAdLoadFailed:(NSError *)error adExtra:(NSDictionary *)adExtra Callback to developer when ad loading fails
- (void)atOnAdShow:(NSDictionary *)adExtra Callback to developer when ad is successfully displayed
- (void)atOnAdShowFailed:(NSError *)error extra:(NSDictionary *)extraDic Callback to developer when ad display fails
- (void)atOnAdClick:(NSDictionary *)adExtra Callback to developer when ad is clicked by user
- (void)atOnAdWillClosed:(NSDictionary *)extra Callback to developer when ad is about to close
- (void)atOnAdClosed:(NSDictionary *)extra Callback to developer when ad is closed
- (void)atOnAdDetailWillShow:(NSDictionary *)extra Callback to developer when ad detail page is about to show
- (void)atOnAdDetailClosed:(NSDictionary *)extra Callback to developer when ad detail page is closed
- (void)atOnAdDeeplinkOrJumpResult:(BOOL)success Callback to developer with ad deeplink jump result
- (void)atOnAdVideoStart:(NSDictionary *)extra Callback to developer when ad video starts playing
- (void)atOnAdVideoEnd:(NSDictionary *)extra Callback to developer when ad video finishes playing
- (void)atOnAdDidFailToPlayVideo:(NSError *)error extra:(NSDictionary *)extraDic Callback to developer when ad video fails to play
- (void)atOnAdDidRevenue:(NSDictionary *)extraDic Callback to developer with ad revenue information
Method Description
- (void)atOnBannerAdLoadedWithView:(UIView *)bannerView adExtra:(NSDictionary *)adExtra Callback to developer when banner ad loads successfully

4. Implementation Steps

4.1 Implement DemoCustomBannerDelegate.h

  1. Import header file #import <AnyThinkSDK.h>
  2. Add property: @property (nonatomic, strong) ATBannerAdStatusBridge * adStatusBridge;
  3. Conform to your third-party ad SDK banner ad callback protocol

Example:

objc Copy
#import <AnyThinkSDK/AnyThinkSDK.h>
#import <Foundation/Foundation.h>
#import "DemoCustomAdapterCommonHeader.h"

@interface DemoCustomBannerDelegate : NSObject<YourBannerViewDelegate>

@property (nonatomic, strong) ATBannerAdStatusBridge * adStatusBridge;

@end

4.2 Implement DemoCustomBannerDelegate.m

  1. Implement your third-party SDK's protocol methods, such as ad load success, ad click, ad close, etc.
  2. In the third-party SDK ad load success event, call to notify us of ad load success and pass back our Banner object, for example:
objc Copy
/**
   Platform ad is ready and can be displayed
 */
- (void)yourBannerAdReadySuccess:(YourBannerView *)bannerAd { // This is the third-party SDK's protocol method, called when ad loads successfully
    // Pass the banner ad object from the third-party ad SDK callback to our mediation SDK
    [self.adStatusBridge atOnBannerAdLoadedWithView:bannerAd adExtra:@{}];
}
  1. In the third-party SDK's ad load failure event, call to notify us of ad load failure, for example:
objc Copy
/**
 * Called after ad request fails
 */
- (void)yourBannerError:(YourBannerView *)bannerAd error:(NSError *)error { // This is the third-party SDK's protocol method, called when ad loading fails
    // Notify us of load failure
    [self.adStatusBridge atOnAdLoadFailed:error adExtra:nil];
}
  1. Refer to our SDK's ATBannerTrackProtocol and ATBaseTrackProtocol protocols, implement other ad events and notify us, for example:
objc Copy
/**
 *  Banner click callback
 */
- (void)yourBannerClicked:(YourBannerView *)bannerAd {
    [self.adStatusBridge atOnAdClick:nil];
}

4.3 Implement DemoCustomBannerAdapter.h

  1. Inherit from DemoCustomBaseAdapter
  2. Import header file #import <AnyThinkSDK.h>
  3. Conform to ATBaseBannerAdapterProtocol protocol

4.4 Implement DemoCustomBannerAdapter.m

  1. Add the following properties:
objc Copy
@interface DemoCustomBannerAdapter()

// Implemented in step 1 of this document
@property (nonatomic, strong) DemoCustomBannerDelegate * bannerDelegate;

// Third-party SDK's banner ad object
@property (nonatomic, strong) YourBannerView *bannerView;

@end
  1. Initialize the bannerDelegate property
objc Copy
#pragma mark - lazy
- (DemoCustomBannerDelegate *)bannerDelegate{
    if (_bannerDelegate == nil) {
        _bannerDelegate = [[DemoCustomBannerDelegate alloc] init];
        _bannerDelegate.adStatusBridge = self.adStatusBridge;
    }
    return _bannerDelegate;
}
  1. Implement the ad loading method:
objc Copy
#pragma mark - Ad load
- (void)loadADWithArgument:(ATAdMediationArgument *)argument {
    dispatch_async(dispatch_get_main_queue(), ^{ // Usually needs to be executed on the main thread
        // Get necessary loading information through the argument object, such as size, create necessary parameters, prepare to pass to the third-party banner loading method, start loading ads
        CGSize bannerSize = CGSizeMake(320, 50);
        if (!CGSizeEqualToSize(argument.bannerSize, CGSizeZero)) {
            bannerSize = argument.bannerSize;
        }
        
        self.bannerView = [[YourBannerView alloc] initWithFrame:CGRectMake(0, 0, bannerSize.width, bannerSize.height)];
        // Note: Set delegate to DemoCustomBannerDelegate
        self.bannerView.delegate = self.bannerDelegate;
        
        YourBannerAdConfigParams *adParam = [[YourBannerAdConfigParams alloc]init];
        adParam.showCloseBtn = NO;
        adParam.interval = 0;
        // Call the third-party ad SDK's loading method
        [self.bannerView loadAdAndShowWithPid:argument.serverContentDic[@"slot_id"] presentVC:argument.viewController adParams:adParam];
    });
}

Last modified: 2025-10-10Powered by