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:
The specific method is as follows:
Abstract method | Parameter description | Return Value | Function | Required |
---|---|---|---|---|
-(instancetype) initWithNetworkCustomInfo:(NSDictionary*)serverInfo localInfo:(NSDictionary*)localInfo | serverInfo: parameter dictionary configured on the server side localInfo: parameter dictionary passed in this time | instancetype | Used to initialize custom adapter | Yes |
-(void) loadADWithInfo: (NSDictionary*)serverInfo localInfo:(NSDictionary*)localInfo completion:(void (^)(NSArray<NSDictionary *> *, NSError *))completion | serverInfo: parameter dictionary configured on the server localInfo: parameter dictionary passed in this time | void | Implement the logic of displaying custom advertising platform loading ads | Yes |
+(BOOL) adReadyWithCustomObject:(id)customObject info:(NSDictionary*)info | customObject: custom advertising object info: parameter dictionary configured on the server side | BOOL | Used to determine whether the rewarded video ads of the custom advertising platform are ready. The status | Yes |
+(void) showRewardedVideo:(ATRewardedVideo*)rewardedVideo inViewController:(UIViewController*)viewController delegate:(id | rewardedVideo: Rewarded video object viewController: current view controller delegate: advertising object proxy | void | The logic of displaying rewarded videos on custom advertising platforms | Yes |
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:
Method | Parameter description | Description |
---|---|---|
-(void) trackRewardedVideoAdLoaded:(id)adObject adExtra:(NSDictionary * )adExtra | adObject: rewarded video ad object adExtra: extended information | Execute a callback to the developer when the ad is loaded successfully |
- (void) trackRewardedVideoAdLoadFailed:(NSError* )error | error: error message | Execute 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* )error | error: playback failure information | Execute a callback to the developer when the ad playback fails |
-(void) trackRewardedVideoAdClick | - | Callback to the developer when the ad is clicked |
-(void) trackRewardedVideoAdCloseRewarded:(BOOL)rewarded | rewarded: whether issue rewards | Execute a callback to the developer when the advertising page is closed |
-(void) trackRewardedVideoAdRewarded | - | Execute a callback to the developer when issuing incentives to users |
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];
}
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