π‘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.
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.
You need to inherit from DemoCustomBaseAdapter and override the relevant methods:
loadADWithArgument: method will be calledadReadyRewardedWithInfo: method will be calledshowRewardedVideoInViewController: 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 |
The rewarded video ad adapter supports the following callback methods, which inherit from the ATBaseTrackProtocol and ATRewardedTrackProtocol protocols:
| 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 |
| 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.1 Implement DemoCustomRewardVideoDelegate.h
Steps:
- Import the header file
#import <AnyThinkSDK.h>- Add property:
@property (nonatomic, strong) ATRewardedAdStatusBridge * adStatusBridge;- 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
Steps:
- 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 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:{}]; }
- 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]; }
- Refer to our SDK's
ATRewardedVideoTrackProtocolandATBaseTrackProtocolprotocols, 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]; }
Steps:
- Inherit from DemoCustomBaseAdapter
- Import the header file
#import <AnyThinkSDK.h>- Conform to the
ATBaseRewardedAdapterProtocolprotocol
Steps:
- 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
- Initialize the
rewardedVideoDelegatepropertyobjc Copy#pragma mark - lazy - (DemoCustomRewardVideoDelegate *)rewardedVideoDelegate{ if (_rewardedVideoDelegate == nil) { _rewardedVideoDelegate = [[DemoCustomRewardVideoDelegate alloc] init]; _rewardedVideoDelegate.adStatusBridge = self.adStatusBridge; } return _rewardedVideoDelegate; }
- 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]; }
- Implement ad display method:
objc Copy#pragma mark - Ad show - (void)showRewardedVideoInViewController:(UIViewController *)viewController { [self.rewardAd showRewardVideoAdFromRootViewController:viewController]; }
- Implement ad ready status check method:
objc Copy#pragma mark - Ad ready - (BOOL)adReadyRewardedWithInfo:(NSDictionary *)info { return self.rewardAd.isAdValid; }