π‘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.
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
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 |
Banner ad adapters support the following callback methods, which inherit from the ATBaseTrackProtocol and ATBannerTrackProtocol protocols:
| 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 |
- Import header file
#import <AnyThinkSDK.h>- Add property:
@property (nonatomic, strong) ATBannerAdStatusBridge * adStatusBridge;- 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
- Implement your third-party SDK's protocol methods, such as ad load success, ad click, ad close, etc.
- 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:@{}]; }
- 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]; }
- Refer to our SDK's
ATBannerTrackProtocolandATBaseTrackProtocolprotocols, implement other ad events and notify us, for example:objc Copy/** * Banner click callback */ - (void)yourBannerClicked:(YourBannerView *)bannerAd { [self.adStatusBridge atOnAdClick:nil]; }
- Inherit from DemoCustomBaseAdapter
- Import header file
#import <AnyThinkSDK.h>- Conform to
ATBaseBannerAdapterProtocolprotocol
- 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
- Initialize the
bannerDelegatepropertyobjc Copy#pragma mark - lazy - (DemoCustomBannerDelegate *)bannerDelegate{ if (_bannerDelegate == nil) { _bannerDelegate = [[DemoCustomBannerDelegate alloc] init]; _bannerDelegate.adStatusBridge = self.adStatusBridge; } return _bannerDelegate; }
- 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]; }); }