Menu

Rewarded video

1. Main development work instructions

1. Create a custom RewardedVideo Adapter class that can inherit NSObject and follow the ATAdAdapter protocol. It is recommended to end with RewardedVideoAdapter. The class name needs to be configured to the custom advertising platform in the TopOn backend.

2. The custom adapter class must implement the method described below:

  • When the SDK needs to request to configure a custom advertising source, it will call the method initWithNetworkCustomInfo: to instantiate the adapter object.
  • Requesting a custom advertising source advertisement will trigger the adapter's loadADWithInfo: method call;
  • When it is necessary to determine whether the custom ad source advertisement has been filled, adReadyWithCustomObject: method call will be triggered.
  • When a custom ad source advertisement needs to be displayed, the showRewardedVideo: method call will be triggered.

The specific method is as follows:

Abstract methodParameter descriptionReturn ValueFunctionRequired
-(instancetype) initWithNetworkCustomInfo:(NSDictionary*)serverInfo localInfo:(NSDictionary*)localInfoserverInfo: parameter dictionary configured on the server side
localInfo: parameter dictionary passed in this time
instancetypeUsed to initialize custom adapterYes
-(void) loadADWithInfo: (NSDictionary*)serverInfo localInfo:(NSDictionary*)localInfo completion:(void (^)(NSArray<NSDictionary *> *, NSError *))completionserverInfo: parameter dictionary configured on the server
localInfo: parameter dictionary passed in this time
voidImplement the logic of displaying custom advertising platform loading adsYes
+(BOOL) adReadyWithCustomObject:(id)customObject info:(NSDictionary*)info customObject: custom advertising object
info: parameter dictionary configured on the server side
BOOLUsed to determine whether the rewarded video ads of the custom advertising platform are ready. The statusYes
+(void) showRewardedVideo:(ATRewardedVideo*)rewardedVideo inViewController:(UIViewController*)viewController delegate:(idrewardedVideo: Rewarded video object
viewController: current view controller
delegate: advertising object proxy
voidThe logic of displaying rewarded videos on custom advertising platformsYes

3. The callback method is described as follows: You need to customize a xxxCustomEvent class, inherit the ATRewardedVideoCustomEvent class, and pass this class add a callback agent corresponding to the custom advertising platform. When the advertising platform has a callback, the corresponding event will be called ATRewardedVideoCustomEvent method and passed back to TopOn SDK.

The specific callback method is described as follows:

MethodParameter descriptionDescription
-(void) trackRewardedVideoAdLoaded:(id)adObject adExtra:(NSDictionary * )adExtraadObject: rewarded video ad object
adExtra: extended information
Execute a callback to the developer when the ad is loaded successfully
- (void) trackRewardedVideoAdLoadFailed:(NSError* )errorerror: error messageExecute a callback to the developer when the ad loading fails
self.customEventMetaDataDidLoadedBlock( );-Creative content Loading success callback (can be omitted when the custom advertising platform rewarded video agent does not have material callback)
-(void) trackRewardedVideoAdShow
-(void) trackRewardedVideoAdVideoStart
-Execute a callback to the developer when the ad playback starts
-(void) trackRewardedVideoAdVideoEnd-Execute a callback to the developer when the ad playback ends
-(void) trackRewardedVideoAdPlayEventWithError:(NSError* )errorerror: playback failure informationExecute a callback to the developer when the ad playback fails
-(void) trackRewardedVideoAdClick-Callback to the developer when the ad is clicked
-(void) trackRewardedVideoAdCloseRewarded:(BOOL)rewardedrewarded: whether issue rewardsExecute a callback to the developer when the advertising page is closed
-(void) trackRewardedVideoAdRewarded-Execute a callback to the developer when issuing incentives to users

2. Specific integration instructions and examples

2.1 Implement advertising loading Adapter class

  1. Create a custom RewardedVideo Adapter class, which can inherit NSObject. It is recommended to end with RewardedVideoAdapter. The class name needs to be configured to the custom advertisement in the TopOn background. Platform.
  2. The custom adapter class must implement the following methods:
  • Implement initWithNetworkCustomInfo : Instantiate the adapter object, where you can perform related initialization of the advertising SDK;
  • Implement the loadADWithInfo: method called when advertising is loaded to trigger the advertising request of the advertising SDK ;
  • Implement the adReadyWithCustomObject: method to inform TopOn SDK whether there are currently ads to fill;
  • Implement the showRewardedVideo: method. When the TopOn SDK triggers ad display, this method will be called to trigger the ad display logic of the ad SDK.

The following is an integration example. For specific projects, please refer to demo:

Create and implement the TTRewardedVideoCustomAdapter class:

//TouTiaoRewardedVideoAdapter.h

#import <AnyThinkRewardedVideo/AnyThinkRewardedVideo.h>
@interface TTRewardedVideoCustomAdapter : NSObject <ATAdAdapter>
@property (nonatomic,copy) void (^metaDataDidLoadedBlock)(void); @end
//TouTiaoRewardedVideoAdapter.m
#import <AnyThinkRewardedVideo/AnyThinkRewardedVideo.h>

@interface TTRewardedVideoCustomAdapter()
@property(nonatomic, readonly) TouTiaoRewardedVideoCustomEvent *customEvent;
@end

@implementation TTRewardedVideoCustomAdapter

/// Adapter initialization method
/// - Parameters:
///   - serverInfo: Data from the server
///   - localInfo: Data from the local
-(instancetype) initWithNetworkCustomInfo:(NSDictionary*)serverInfo localInfo:(NSDictionary*)localInfo {
    self = [super init];
    if (self != nil) {
    //TODO: add some code for initialize Network SDK
    }
    return self;
}

/// Adapter sends a load request, means the ad source sends an ad load request
/// - Parameters:
///   - serverInfo: Data from the server
///   - localInfo: Data from the local
///   - completion: completion
-(void) loadADWithInfo:(NSDictionary*)serverInfo localInfo:(NSDictionary*)localInfo completion:(void (^)(NSArray<NSDictionary *> *, NSError *))completion {
    _customEvent = [[TouTiaoRewardedVideoCustomEvent alloc] initWithInfo:serverInfo localInfo:localInfo];
    _customEvent.requestCompletionBlock = completion;

    BURewardedVideoModel *model = [[BURewardedVideoModel alloc] init];
    NSDictionary *extra = localInfo;
    if (extra[kATAdLoadingExtraUserIDKey] != nil) {
        model.userId = extra[kATAdLoadingExtraUserIDKey];
    }
    if (extra[kATAdLoadingExtraMediaExtraKey] != nil) {
        model.extra = extra[kATAdLoadingExtraMediaExtraKey];
    }

    _expressRvAd = [[BUNativeExpressRewardedVideoAd alloc] initWithSlotID:serverInfo[@"slot_id"] rewardedVideoModel:model];
    _expressRvAd.rewardedVideoModel = model;
    _expressRvAd.delegate = _customEvent;
    [_expressRvAd loadAdData];
}

/// Check whether the ad source is ready
/// - Parameters:
///   - customObject: ad source object
///   - info: info
+(BOOL) adReadyWithCustomObject:(id)customObject info:(NSDictionary*)info {
    return ((BUNativeExpressRewardedVideoAd *)customObject).adValid;
}

+(void) showRewardedVideo:(ATRewardedVideo*)rewardedVideo inViewController:(UIViewController*)viewController delegate:(id<ATRewardedVideoDelegate>)delegate {
    TouTiaoRewardedVideoCustomEvent *customEvent = (TouTiaoRewardedVideoCustomEvent*)rewardedVideo.customEvent;
    customEvent.delegate = delegate;
    [((BUNativeExpressRewardedVideoAd *)rewardedVideo.customObject) showAdFromRootViewController:viewController];
}

2.2 CustomEvent class that implements advertising callback

It is necessary to customize a xxxCustomEvent class, inherit the ATRewardedVideoCustomEvent class, and add the callback agent corresponding to the custom advertising platform through this class. When the advertising platform has a callback, the method of calling ATRewardedVideoCustomEvent for the corresponding event will be passed back to TopOn SDK.

The following is an integration example. For specific projects, please refer to demo:

Create and implement the TouTiaoRewardedVideoCustomEvent class:

@interface TouTiaoRewardedVideoCustomEvent : ATRewardedVideoCustomEvent<BUNativeExpressRewardedVideoAdDelegate>

@end

- (void)nativeExpressRewardedVideoAdDidLoad:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdDidLoad:");
    [self trackRewardedVideoAdLoaded:rewardedVideoAd adExtra:nil];
}

- (void)nativeExpressRewardedVideoAd:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd didFailWithError:(NSError *_Nullable)error {
    NSLog(@"%@",[NSString stringWithFormat:@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdDidLoad:didFailWithError:%@",error]);
    if (!_isFailed) {
        [self trackRewardedVideoAdLoadFailed:error];
        _isFailed = true;
    }
}

- (void)nativeExpressRewardedVideoAdDidDownLoadVideo:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdDidDownLoadVideo:");
}

- (void)nativeExpressRewardedVideoAdViewRenderSuccess:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdViewRenderSuccess:");
}

- (void)nativeExpressRewardedVideoAdViewRenderFail:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd error:(NSError *_Nullable)error {
    NSLog(@"%@",[NSString stringWithFormat:@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdViewRenderFail:error:%@",error]);
    if (!_isFailed) {
        [self trackRewardedVideoAdLoadFailed:error];
        _isFailed = true;
    }
}

- (void)nativeExpressRewardedVideoAdWillVisible:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdWillVisible:");
}

- (void)nativeExpressRewardedVideoAdDidVisible:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdDidVisible:");
    [self trackRewardedVideoAdShow];
    [self trackRewardedVideoAdVideoStart];
}

- (void)nativeExpressRewardedVideoAdWillClose:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdWillClose:");
}

- (void)nativeExpressRewardedVideoAdDidClose:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdDidClose:");
    [self trackRewardedVideoAdCloseRewarded:self.rewardGranted];
}

- (void)nativeExpressRewardedVideoAdDidClick:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdDidClick:");
    [self trackRewardedVideoAdClick];
}

- (void)nativeExpressRewardedVideoAdDidClickSkip:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdDidClickSkip:");
}

- (void)nativeExpressRewardedVideoAdDidPlayFinish:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd didFailWithError:(NSError *_Nullable)error {
    NSLog(@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdDidPlayFinish:didFailWithError:");
    if (error == nil) {
        [self trackRewardedVideoAdVideoEnd];
    } else {
        [self trackRewardedVideoAdPlayEventWithError:error];
    }
}

- (void)nativeExpressRewardedVideoAdServerRewardDidSucceed:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd verify:(BOOL)verify {
    NSLog(@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdServerRewardDidSucceed:verify:");
    [self trackRewardedVideoAdRewarded];
}

- (void)nativeExpressRewardedVideoAdServerRewardDidFail:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"TouTiaoRewardedVideoCustomEvent::nativeExpressRewardedVideoAdServerRewardDidFail:");
    self.rewardGranted = NO;
}

- (NSString *)networkUnitId {
    return self.serverInfo[@"slot_id"];
}

Note: Before issuing an incentive callback to the user, you need to set rewardGranted to YES to identify whether it has been Distribute rewards

Previous
Basic process
Next
Interstitials
Last modified: 2025-05-30Powered by