Menu

Custom Interstitial 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: DemoCustomInterstitialAdapter, you need to create the corresponding DemoCustomInterstitialAdapter.m file.

Copy
Interstitial/
β”œβ”€β”€ DemoCustomInterstitialAdapter.h          # Interstitial adapter header file
β”œβ”€β”€ DemoCustomInterstitialAdapter.m          # Interstitial adapter implementation file
β”œβ”€β”€ DemoCustomInterstitialDelegate.h         # Interstitial delegate header file
└── DemoCustomInterstitialDelegate.m         # Interstitial delegate implementation file

2. 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
  • When developers call the ad ready status check API, the custom Adapter's adReadyInterstitialWithInfo: method will be called
  • When developers call the ad display API, the custom Adapter's showInterstitialInViewController: 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
- (void)showInterstitialInViewController:(UIViewController *)viewController viewController: The UIViewController passed when displaying the ad Implement the logic for displaying custom ads
- (BOOL)adReadyInterstitialWithInfo:(NSDictionary *)info info: Ad information dictionary Used to determine if the custom ad is ready before displaying

3. Callback Event Description

The interstitial ad adapter supports the following callback methods, which are inherited from the ATBaseTrackProtocol and ATInterstitialTrackProtocol protocols:

3.1 Basic Ad Event Callbacks

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

3.2 Interstitial Ad Specific Event Callbacks

Method Description
- (void)atOnInterstitialAdLoadedExtra:(NSDictionary *)adExtra Called when interstitial ad loads successfully

4. Implementation Steps

4.1 Implement DemoCustomInterstitialDelegate.h

  1. Import header file #import <AnyThinkSDK.h>
  2. Add property: @property (nonatomic, strong) ATInterstitialAdStatusBridge * adStatusBridge;
  3. Conform to the interstitial ad callback protocol of the ad platform you're integrating, for example MSInterstitialDelegate in this case
    Example:
objc Copy
#import <AnyThinkSDK/AnyThinkSDK.h>
#import <Foundation/Foundation.h>
#import "DemoCustomAdapterCommonHeader.h"

@interface DemoCustomInterstitialDelegate : NSObject<MSInterstitialDelegate>

@property (nonatomic, strong) ATInterstitialAdStatusBridge * adStatusBridge;

@end

4.2 Implement DemoCustomInterstitialDelegate.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's ad load success event, call to notify us that the ad loaded successfully, for example:
objc Copy
/**
   Platform ad display is ready, can proceed with display. Call show interface in this callback to display ad
 */
- (void)msInterstitialAdReadySuccess:(MSInterstitialAd *)msInterstitialAd { //This is the third-party SDK's protocol method, called when ad loads successfully
    [self.adStatusBridge atOnInterstitialAdLoadedExtra:@{}];
}
  1. In the third-party SDK's ad load failure event, call to notify us that the ad loading failed, for example:
objc Copy
/**
 *  Ad preload failure callback
 *  Description: Called when receiving ad data from server fails
 */
- (void)msInterstitialError:(MSInterstitialAd *)msInterstitialAd error:(NSError *)error {//This is the third-party SDK's protocol method, called when ad loading fails
    //Notify us of loading failure
    [self.adStatusBridge atOnAdLoadFailed:error adExtra:nil];
}
  1. Implement other ad events and notify us, for example:
objc Copy
/**
 *  Interstitial ad click callback
 */
- (void)msInterstitialClicked:(MSInterstitialAd *)msInterstitialAd {
    [self.adStatusBridge atOnAdClick:nil];
}

/**
 *  Interstitial ad view display success callback
 *  Description: Called when interstitial ad displays successfully
 */
- (void)msInterstitialShow:(MSInterstitialAd *)msInterstitialAd {
    [self.adStatusBridge atOnAdShow:nil];
}

/**
 *  Interstitial ad display end callback
 *  Description: Called when interstitial ad display ends
 */
- (void)msInterstitialClosed:(MSInterstitialAd *)msInterstitialAd {
    [self.adStatusBridge atOnAdClosed:nil];
}

/**
   Platform ad display failure
   Description: May be caused by abnormal ad material or third-party exceptions preventing ad exposure
 */
- (void)msInterstitialAdShowFail:(MSInterstitialAd *)msInterstitialAd error:(NSError *)error {
    [self.adStatusBridge atOnAdShowFailed:error extra:nil];
}

/**
 *  Full-screen ad page closed
 */
- (void)msInterstitialDetailClosed:(MSInterstitialAd *)msInterstitialAd {
    [self.adStatusBridge atOnAdDetailClosed:nil];
}

4.3 Implement DemoCustomInterstitialAdapter.h

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

4.4 Implement DemoCustomInterstitialAdapter.m

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

// Implemented in section 4.1 of this document
@property (nonatomic, strong) DemoCustomInterstitialDelegate * interstitialDelegate;

// Third-party SDK's interstitial ad object
@property (nonatomic, strong) MSInterstitialAd *interstitialAd;

@end
  1. Initialize the interstitialDelegate property
objc Copy
#pragma mark - lazy
- (DemoCustomInterstitialDelegate *)interstitialDelegate{
    if (_interstitialDelegate == nil) {
        _interstitialDelegate = [[DemoCustomInterstitialDelegate alloc] init];
        _interstitialDelegate.adStatusBridge = self.adStatusBridge;
    }
    return _interstitialDelegate;
}
  1. Implement ad loading method:
objc Copy
#pragma mark - Ad load
- (void)loadADWithArgument:(ATAdMediationArgument *)argument {
    //Get necessary loading information through argument object, create necessary parameters, prepare to pass to third-party interstitial loading method, start loading ad
    self.interstitialAd = [[MSInterstitialAd alloc] init];
    //Note: Set delegate to DemoCustomInterstitialDelegate
    self.interstitialAd.delegate = self.interstitialDelegate;
    
    MSInterstitialAdConfigParams *adParam = [[MSInterstitialAdConfigParams alloc]init];
    adParam.videoMuted = [argument.localInfoDic[@"video_muted"] intValue] == 0 ? NO : YES;
    adParam.isNeedCloseAdAfterClick = [argument.localInfoDic[@"click_close"] intValue] == 0 ? NO : YES;
     
    [self.interstitialAd loadAdWithPid:argument.serverContentDic[@"slot_id"] adConfigParams:adParam];
}
  1. Implement ad display method:
objc Copy
#pragma mark - Ad show
- (void)showInterstitialInViewController:(UIViewController *)viewController {
    [self.interstitialAd showAdFromRootViewController:viewController];
}
  1. Implement ad ready status check method:
objc Copy
#pragma mark - Ad ready
- (BOOL)adReadyInterstitialWithInfo:(NSDictionary *)info {
    return self.interstitialAd.isAdValid;
}

Last modified: 2025-10-10Powered by