1. Create a custom Interstitial Adapter class that can inherit NSObject. And follow the ATAdAdapter protocol, it is recommended to end with InterstitialAdapter, and 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 description As follows:
The specific method is explained as follows:
Method | Parameter description | Return value | Description | 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 customization 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: server-side configuration parameter dictionary | BOOL | Used to determine the custom advertising platform Is the rewarded video ad ready? | Yes |
+(void) showInterstitial:(ATInterstitial *)interstitial inViewController:(UIViewController*)viewController delegate:(id | interstitial: interstitial ad object viewController: current view controller delegate: ad object proxy | void | Implement the logic of displaying custom advertising platform interstitial | Yes |
3. The callback method is described as follows: You need to customize a xxxCustomEvent Class, inherit the ATInterstitialCustomEvent class, and use this class to add the callback agent corresponding to the screen opening of the custom advertising platform. When the advertising platform has a callback, the method of calling ATInterstitialCustomEvent for the corresponding event is returned to the TopOn SDK.
The specific callback method is described as follows:
Callback method | Parameter description | Description |
---|---|---|
-(void) trackInterstitialAdLoaded:(id)interstitialAd adExtra:(NSDictionary * )adExtra | interstitialAd: interstitial ad object adExtra: extended information | Execute a callback to the developer when the ad is loaded successfully |
-(void) trackInterstitialAdLoadFailed:(NSError* )error | error: error message | Execute a callback to the developer when the ad loading fails |
self.customEventMetaDataDidLoadedBlock( ) | - | Creative content loading Success callback (this is not required when the custom advertising platform rewarded video agent does not have material callback) |
-(void) trackInterstitialAdShow | - | When the ad page opens Execute callback to developer |
-(void) trackInterstitialAdShowFailed:(NSError* )error | error: error message | Callback executed when the ad page fails to open For developers |
-(void) trackInterstitialAdVideoStart | - | Execute a callback to the developer when the ad playback starts |
-(void) trackInterstitialAdVideoEnd | - | Execute a callback to the developer when the ad is played |
-(void) trackInterstitialAdDidFailToPlayVideo:(NSError* )error | error: playback failure information | Execute a callback to the developer when the ad playback fails |
-(void) trackInterstitialAdClick | - | Callback to the developer executed when the ad is clicked |
-(void) trackInterstitialAdClose | - | Executed when the advertising page is closed Call back to developer |
1. Create a custom Interstitial Adapter class, which can inherit NSObject. It is recommended to end with InterstitialAdapter. The class name needs to be configured to the custom advertising platform in the TopOn backend;
2. The custom adapter class must implement the following methods:
The following is an integration example. For specific projects, please refer to demo:
Create and implement the TTInterstitialCustomAdapter class:
//TouTiaoInterstitialCustomAdapter.h
@interface TTInterstitialCustomAdapter : NSObject<ATAdAdapter>
@property (nonatomic,copy) void (^metaDataDidLoadedBlock)(void);
@end
//TouTiaoInterstitialCustomAdapter.m
#import <AnyThinkInterstitial/AnyThinkInterstitial.h>
@interface TTInterstitialCustomAdapter()
@property(nonatomic, readonly) TouTiaoInterstitialCustomEvent *customEvent;
@end
@implementation TTInterstitialCustomAdapter
/// 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 = [[TouTiaoInterstitialCustomEvent alloc] initWithInfo:serverInfo localInfo:localInfo];
_customEvent.requestCompletionBlock = completion;
// _customEvent.customEventMetaDataDidLoadedBlock = self.metaDataDidLoadedBlock;
CGSize adSize = [serverInfo[@"size"] respondsToSelector:@selector(CGSizeValue)] ? [serverInfo[@"size"] CGSizeValue] : CGSizeMake(300.0f, 300.0f);
_interstitial = [[BUNativeExpressInterstitialAd alloc] initWithSlotID:serverInfo[@"slot_id"] adSize:adSize];
_interstitial.delegate = _customEvent;
[_interstitial loadAdData];
}
/// Check whether the ad source is ready
/// - Parameters:
/// - customObject: ad source object
/// - info: info
+(BOOL) adReadyWithCustomObject:(id)customObject info:(NSDictionary*)info {
return ((BUNativeExpressInterstitialAd *)customObject).adValid;
}
+(void) showInterstitial:(ATInterstitial*)interstitial inViewController:(UIViewController*)viewController delegate:(id<ATInterstitialDelegate>)delegate {
BUNativeExpressInterstitialAd *ttInterstitial = interstitial.customObject;
interstitial.customEvent.delegate = delegate;
[ttInterstitial showAdFromRootViewController:viewController];
}
It is necessary to customize a xxxCustomEvent class, inherit the ATInterstitialCustomEvent class, and add a custom advertising platform through this class to open the corresponding The callback agent of the screen. When there is a callback from the advertising platform, the method of calling ATInterstitialCustomEvent for the corresponding event is passed back to TopOn SDK.
The following is an integration example. For specific projects, please refer to demo:
Create and implement the TouTiaoInterstitialCustomEvent class:
- (void)nativeExpresInterstitialAdDidLoad:(BUNativeExpressInterstitialAd *)interstitialAd {
NSLog(@"TouTiaoInterstitialCustomEvent::interstitialAdDidLoad:");
[self trackInterstitialAdLoaded:interstitialAd adExtra:nil];
}
- (void)nativeExpresInterstitialAd:(BUNativeExpressInterstitialAd *)interstitialAd didFailWithError:(NSError * __nullable)error {
NSLog(@"%@",[NSString stringWithFormat:@"TouTiaoInterstitialCustomEvent::interstitialAd:didFailWithError:%@", error]);
[self trackInterstitialAdLoadFailed:error];
}
- (void)nativeExpresInterstitialAdWillVisible:(BUNativeExpressInterstitialAd *)interstitialAd {
NSLog(@"TouTiaoInterstitialCustomEvent::interstitialAdWillVisible:");
[self trackInterstitialAdShow];
}
- (void)nativeExpresInterstitialAdDidClick:(BUNativeExpressInterstitialAd *)interstitialAd {
NSLog(@"TouTiaoInterstitialCustomEvent::interstitialAdDidClick:");
[self trackInterstitialAdClick];
}
- (void)nativeExpresInterstitialAdDidClose:(BUNativeExpressInterstitialAd *)interstitialAd {
NSLog(@"TouTiaoInterstitialCustomEvent::interstitialAdDidClose:");
[self trackInterstitialAdClose];
}
- (void)nativeExpresInterstitialAdWillClose:(BUNativeExpressInterstitialAd *)interstitialAd {
NSLog(@"TouTiaoInterstitialCustomEvent::interstitialAdWillClose:");
}
- (NSString *)networkUnitId {
return self.serverInfo[@"slot_id"];
}
Note: When implementing callback events for interstitial ads on a custom advertising platform, if there are no callback events related to video playback and end, no return is required.