π‘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.
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
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 |
The interstitial ad adapter supports the following callback methods, which are inherited from the ATBaseTrackProtocol and ATInterstitialTrackProtocol protocols:
| 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 |
| Method | Description |
|---|---|
| - (void)atOnInterstitialAdLoadedExtra:(NSDictionary *)adExtra | Called when interstitial ad loads successfully |
- Import header file
#import <AnyThinkSDK.h>- Add property:
@property (nonatomic, strong) ATInterstitialAdStatusBridge * adStatusBridge;- Conform to the interstitial ad callback protocol of the ad platform you're integrating, for example
MSInterstitialDelegatein 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
- Implement your third-party SDK's protocol methods, such as ad load success, ad click, ad close, etc.
- 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:@{}]; }
- 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]; }
- 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]; }
- Inherit from DemoCustomBaseAdapter
- Import header file
#import <AnyThinkSDK.h>- Conform to
ATBaseInterstitialAdapterProtocolprotocol
- 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
- Initialize the
interstitialDelegatepropertyobjc Copy#pragma mark - lazy - (DemoCustomInterstitialDelegate *)interstitialDelegate{ if (_interstitialDelegate == nil) { _interstitialDelegate = [[DemoCustomInterstitialDelegate alloc] init]; _interstitialDelegate.adStatusBridge = self.adStatusBridge; } return _interstitialDelegate; }
- 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]; }
- Implement ad display method:
objc Copy#pragma mark - Ad show - (void)showInterstitialInViewController:(UIViewController *)viewController { [self.interstitialAd showAdFromRootViewController:viewController]; }
- Implement ad ready status check method:
objc Copy#pragma mark - Ad ready - (BOOL)adReadyInterstitialWithInfo:(NSDictionary *)info { return self.interstitialAd.isAdValid; }