Menu

Interstitials

1. Main development work instructions

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:

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

The specific method is explained as follows:

MethodParameter descriptionReturn valueDescriptionRequired
-(instancetype) initWithNetworkCustomInfo:(NSDictionary *)serverInfo localInfo:(NSDictionary *)localInfoserverInfo: parameter dictionary configured on the server side
localInfo: parameter dictionary passed in this time
instancetypeUsed to initialize customization 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 *)infocustomObject: custom advertising object
info: server-side configuration parameter dictionary
BOOLUsed to determine the custom advertising platform Is the rewarded video ad ready?Yes
+(void) showInterstitial:(ATInterstitial *)interstitial inViewController:(UIViewController*)viewController delegate:(idinterstitial: interstitial ad object
viewController: current view controller
delegate: ad object proxy
voidImplement the logic of displaying custom advertising platform interstitialYes

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 methodParameter descriptionDescription
-(void) trackInterstitialAdLoaded:(id)interstitialAd adExtra:(NSDictionary * )adExtrainterstitialAd: interstitial ad object
adExtra: extended information
Execute a callback to the developer when the ad is loaded successfully
-(void) trackInterstitialAdLoadFailed:(NSError* )errorerror: error messageExecute 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* )errorerror: error messageCallback 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* )errorerror: playback failure informationExecute 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

2. Specific integration instructions and examples

2.1 Adapter class to implement advertising loading

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:

  • 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 ad request of the advertising SDK.
  • Implement the adReadyWithCustomObject: method to inform TopOn SDK whether there are currently ads to fill.
  • Implement the showInterstitial: method, which will be called when TopOn SDK triggers ad display The method triggers the ad display logic of the advertising SDK.

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];
}

2.2 CustomEvent class that implements advertising callback

  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.

Previous
Rewarded video
Next
Splash ads
Last modified: 2025-05-30Powered by