Menu

Custom Rewarded Video Ad Adapter

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

Copy
RewardVideo/
β”œβ”€β”€ DemoCustomRewardVideoAdapter.h          # Rewarded video adapter header file
β”œβ”€β”€ DemoCustomRewardVideoAdapter.m          # Rewarded video adapter implementation file
β”œβ”€β”€ DemoCustomRewardVideoDelegate.h         # Rewarded video delegate header file
└── DemoCustomRewardVideoDelegate.m         # Rewarded video delegate implementation file

Friendly Reminder: The class name can be customized, but it must match the custom ad platform class name configured in the backend. For example, if the adapter class name added in the backend is: DemoCustomRewardVideoAdapter, then you should create the corresponding DemoCustomRewardVideoAdapter.m 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
  • When developers call the ad ready status check API, the custom Adapter's adReadyRewardedWithInfo: method will be called
  • When developers call the ad display API, the custom Adapter's showRewardedVideoInViewController: method will be called
Method Parameter Description Return Value Purpose
- (void)loadADWithArgument:(ATAdMediationArgument *)argument argument: Contains parameters from server and local configuration void Used to get server and local configuration parameters, implement custom ad loading logic
- (void)showRewardedVideoInViewController:(UIViewController *)viewController viewController: The UIViewController passed when displaying the ad void Implement the logic for displaying custom ads
- (BOOL)adReadyRewardedWithInfo:(NSDictionary *)info info: Ad information dictionary BOOL Used to determine if the custom ad is ready before displaying

3. Callback Method Description

The rewarded video ad adapter supports the following callback methods, which inherit from the ATBaseTrackProtocol and ATRewardedTrackProtocol protocols:

3.1 Basic Ad Event Callbacks

Method Description
- (void)atOnAdMetaLoadFinish:(NSDictionary *)adExtra Executed callback to developers when ad data loading is complete
- (void)atOnAdLoadFailed:(NSError *)error adExtra:(NSDictionary *)adExtra Executed callback to developers when ad loading fails
error: Error information
- (void)atOnAdShow:(NSDictionary *)adExtra Executed callback to developers when ad display is successful
- (void)atOnAdShowFailed:(NSError *)error extra:(NSDictionary *)extraDic Executed callback to developers when ad display fails
error: Error information
- (void)atOnAdClick:(NSDictionary *)adExtra Executed callback to developers when ad is clicked by user
- (void)atOnAdWillClosed:(NSDictionary *)extra Executed callback to developers when ad is about to close
- (void)atOnAdClosed:(NSDictionary *)extra Executed callback to developers when ad is closed
- (void)atOnAdDetailWillShow:(NSDictionary *)extra Executed callback to developers when ad detail page is about to show
- (void)atOnAdDetailClosed:(NSDictionary *)extra Executed callback to developers when ad detail page is closed
- (void)atOnAdDeeplinkOrJumpResult:(BOOL)success Ad Deeplink jump result callback to developers
- (void)atOnAdVideoStart:(NSDictionary *)extra Executed callback to developers when ad video starts playing
- (void)atOnAdVideoEnd:(NSDictionary *)extra Executed callback to developers when ad video playback ends
- (void)atOnAdDidFailToPlayVideo:(NSError *)error extra:(NSDictionary *)extraDic Executed callback to developers when ad video playback fails
error: Error information
- (void)atOnAdDidRevenue:(NSDictionary *)extraDic Ad revenue callback to developers

3.2 Rewarded Video Ad Specific Event Callbacks

Method Description
- (void)atOnRewardedAdLoadedExtra:(NSDictionary *)adExtra Executed callback to developers when rewarded video ad loads successfully
- (void)atOnRewardedVideoAdRewarded Executed callback to developers when rewarded video user receives reward
- (BOOL)getRewardGranted Get the status of whether reward has been granted
- (void)atOnRewardedVideoAdRewardedFailWithExtra:(NSDictionary *)adExtra Executed callback to developers when rewarded video reward granting fails

4. Implementation Steps

4.1 Implement DemoCustomRewardVideoDelegate.h

Steps:

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

Final result:

objc Copy
// Import header files
#import <AnyThinkSDK/AnyThinkSDK.h>
#import <Foundation/Foundation.h>

@interface DemoCustomRewardVideoDelegate : NSObject<YourCustomRewardVideoAdDelegate>

@property (nonatomic, strong) ATRewardedAdStatusBridge * adStatusBridge;

@end

4.2 Implement DemoCustomRewardVideoDelegate.m

Steps:

  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 ad loading is successful, for example:
objc Copy
/**
 Video data download success callback, already downloaded videos will callback directly, call show interface in this callback
 @param msRewardVideoAd MSRewardVideoAd instance
 */
- (void)msRewardVideoCached:(MSRewardVideoAd *)msRewardVideoAd { // This is the third-party SDK's protocol method, called when ad loads successfully
    [self.adStatusBridge atOnRewardedAdLoadedExtra:{}];
}
  1. In the third-party SDK's ad load failure event, call to notify us that ad loading failed, for example:
objc Copy
/**
 Video ad various error information callback
 Callback description: If this callback is received, it means this request has failed
 @param msRewardVideoAd MSRewardVideoAd instance
 @param error Specific error information
 */
- (void)msRewardVideoError:(MSRewardVideoAd *)msRewardVideoAd 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. Refer to our SDK's ATRewardedVideoTrackProtocol and ATBaseTrackProtocol protocols, implement other ad events and notify us, for example:
objc Copy
/**
 Video ad information click callback
 @param msRewardVideoAd MSRewardVideoAd instance
 */
- (void)msRewardVideoClicked:(MSRewardVideoAd *)msRewardVideoAd {
    [self.adStatusBridge atOnAdClick:nil];
}

/**
 Video ad exposure callback
 @param msRewardVideoAd MSRewardVideoAd instance
 */
- (void)msRewardVideoShow:(MSRewardVideoAd *)msRewardVideoAd {
    // Ad display success callback
    [self.adStatusBridge atOnAdShow:nil];
}

/**
 Video playback page close callback
 @param msRewardVideoAd MSRewardVideoAd instance
 */
- (void)msRewardVideoClosed:(MSRewardVideoAd *)msRewardVideoAd {
    [self.adStatusBridge atOnAdClosed:nil];
}

/**
 Video ad start playing callback
 @param msRewardVideoAd MSRewardVideoAd instance
 */
- (void)msRewardVideoStartPlaying:(MSRewardVideoAd *)msRewardVideoAd {
    // Video start playing callback
    [self.adStatusBridge atOnAdVideoStart:nil];
}

/**
 Video ad video playback complete
 @param msRewardVideoAd MSRewardVideoAd instance
 */
- (void)msRewardVideoFinish:(MSRewardVideoAd *)msRewardVideoAd {
    // Video playback complete callback
    [self.adStatusBridge atOnAdVideoEnd:nil];
}

/**
 Video ad playback reaches reward condition callback
 @param msRewardVideoAd MSRewardVideoAd instance
 @param adInfo Reward information
 */
- (void)msRewardVideoReward:(MSRewardVideoAd *)msRewardVideoAd extInfo:(NSDictionary *)adInfo {
    if ([[adInfo valueForKey:@"rewardVerify"] intValue] == 1) {
        [self.adStatusBridge atOnRewardedVideoAdRewarded];
    }
}

/**
 Rewarded video render failure
 */
- (void)msRewardVideoRenderFail:(MSRewardVideoAd *)msRewardVideoAd error:(NSError *)error {
    [self.adStatusBridge atOnAdShowFailed:error extra:nil];
}

/**
 Video ad playback exception callback, called when ad is invalid or error occurs during playback
 @param msRewardVideoAd MSRewardVideoAd instance
 @param error Playback error information
 */
- (void)msRewardVideoPlayingError:(MSRewardVideoAd *)msRewardVideoAd error:(NSError *)error {
    [self.adStatusBridge atOnAdDidFailToPlayVideo:error extra:nil];
}

4.3 Implement DemoCustomRewardVideoAdapter.h

Steps:

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

4.4 Implement DemoCustomRewardVideoAdapter.m

Steps:

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

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

// Third-party SDK's rewarded video ad object
@property (nonatomic, strong) MSRewardVideoAd *rewardAd;

@end
  1. Initialize the rewardedVideoDelegate property
objc Copy
#pragma mark - lazy
- (DemoCustomRewardVideoDelegate *)rewardedVideoDelegate{
    if (_rewardedVideoDelegate == nil) {
        _rewardedVideoDelegate = [[DemoCustomRewardVideoDelegate alloc] init];
        _rewardedVideoDelegate.adStatusBridge = self.adStatusBridge;
    }
    return _rewardedVideoDelegate;
}
  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 rewarded video loading method, start loading ad
    self.rewardAd = [[MSRewardVideoAd alloc] init];
    // Note: Set delegate to DemoCustomRewardVideoDelegate
    self.rewardAd.delegate = self.rewardedVideoDelegate;
    
    MSRewardAdConfigParams *adParam = [[MSRewardAdConfigParams alloc]init];
    adParam.userId = argument.localInfoDic[kATAdLoadingExtraUserIDKey];
    adParam.videoMuted = [argument.localInfoDic[@"video_muted"] intValue] == 0 ? NO : YES;
 
    [self.rewardAd loadRewardVideoAdWithPid:argument.serverContentDic[@"slot_id"] adConfigParams:adParam];
}
  1. Implement ad display method:
objc Copy
#pragma mark - Ad show
- (void)showRewardedVideoInViewController:(UIViewController *)viewController {
    [self.rewardAd showRewardVideoAdFromRootViewController:viewController];
}
  1. Implement ad ready status check method:
objc Copy
#pragma mark - Ad ready
- (BOOL)adReadyRewardedWithInfo:(NSDictionary *)info {
    return self.rewardAd.isAdValid;
}

Last modified: 2025-10-10Powered by