Menu

Splash ads

1. Main development work description

  1. Create a custom Splash Adapter class that can inherit NSObject , and follow the ATAdAdapter protocol, it is recommended to end with SplashAdapter, and the class name needs to be configured to the custom advertising platform in the TopOn backend;
  2. The custom adapter class must be implemented as described below:
  • When the SDK needs to request the configuration of a custom advertising source, it will call the method initWithNetworkCustomInfo: 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 whether Defining whether the ad source ads have been filled will trigger the adReadyWithCustomObject: method call.
  • When a custom ad source open-screen ad needs to be displayed, the showSplash: method will be triggered. transfer.
    The specific method is explained as follows:
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 loading open-screen ads on the custom advertising platform. Yes
+ (BOOL)adReadyWithCustomObject:(id)customObject info:(NSDictionary*)infocustomObject: Custom advertising object
info: Parameter dictionary configured on the server side
BOOLUsed to determine whether the open-screen advertisement of the custom advertising platform is readyYes
+ (void)showSplash:(ATSplash *)splash localInfo:(NSDictionary *)localInfo delegate:(id)delegatesplash: This time loads the passed object
localInfo: This time loads the passed parameter dictionary, including the window and other parameters passed in the show ad
delegate: indicates the AD object agent
voidImplement the logic of displaying open-screen ads on a custom advertising platform. Note that this is a class methodYes

1.Create a class that inherits NSObject. The name of this class can include the name of the custom advertising platform and end with SplashAdapter.

2.Create a class that inherits ATSplashCustomEvent. The name of this class can be It should also contain the name of your custom advertising platform and end with SplashCustomEvent.
3. Introduce the following header file into the custom SplashAdapter class.

3. The callback method is described as follows: You need to customize a xxxCustomEvent class, inherit the ATSplashCustomEvent class, and add the callback agent corresponding to the screen opening of the custom advertising platform through this class. When the advertising platform has During the callback, the method of calling ATSplashCustomEvent for the corresponding event is passed back to TopOn SDK.

The specific callback method is described as follows:

Callback methodParameter descriptionDescription
-(void) trackSplashAdLoaded:(id)splashAd adExtra:(NSDictionary *)adExtrasplashAd: advertising object
adExtra: extended information
Execute a callback to TopOn SDK when the ad is loaded successfully
-(void) trackSplashAdLoadFailed:(NSError*)errorerror: error messageExecute a callback to TopOn SDK when the ad loading fails
-(void) trackSplashAdClick-The callback executed when the ad is clicked is sent to TopOn SDK
-(void) trackSplashAdShow-Callback to TopOn executed when the ad is displayed SDK
-(void) trackSplashAdClosed-Callback to TopOn SDK executed when the ad is closed
-(void) trackSplashAdCountdownTime:(NSInteger)countdowncountdown: current countdown timeImplements custom buttons and countdown related parameters. After the countdown starts, call back the current countdown time to TopOn SDK

2. Specific integration instructions and examples

2.1 Implement the Adapter class for advertising loading

1. Create a custom Splash Adapter class that can inherit NSObject. It is recommended to use At the end of SplashAdapter, 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 as follows:

  • Implement initWithNetworkCustomInfo: instantiate the adapter object, where you can perform advertising SDK related initialization.
  • Implement advertising The loadADWithInfo: method called during loading triggers the ad request of the advertising SDK.
  • Implements the adReadyWithCustomObject: method, which is used to inform the TopOn SDK whether there are currently ads to fill.
  • Implement the showSplash: 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 ToutiaoCustomSplashAdapter class:

#import <AnyThinkSplash/AnyThinkSplash.h>

@interface ToutiaoCustomSplashAdapter()<ATAdAdapter>
@property(nonatomic, readonly) TouTiaoSplashCustomEvent *customEvent;
@end

@implementation ToutiaoCustomSplashAdapter

/// 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 {
    NSDictionary *extra = localInfo;
    
    NSTimeInterval tolerateTimeout = localInfo[kATSplashExtraTolerateTimeoutKey] ? [localInfo[kATSplashExtraTolerateTimeoutKey] doubleValue] : 5.0;
    NSDate *curDate = [NSDate date];
    if (tolerateTimeout > 0) {
        _customEvent = [[TouTiaoSplashCustomEvent alloc] initWithInfo:serverInfo localInfo:localInfo];
        _customEvent.requestCompletionBlock = completion;
        _customEvent.expireDate = [curDate dateByAddingTimeInterval:tolerateTimeout];;
        
        dispatch_async(dispatch_get_main_queue(), ^{
            self->_splashView = [[BUSplashAdView alloc] initWithSlotID:serverInfo[@"slot_id"] frame:CGRectMake(.0f, .0f, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds))];
            self->_splashView.tolerateTimeout = tolerateTimeout;
            self->_splashView.delegate = self->_customEvent;
            self->_customEvent.ttSplashView = (UIView*)self->_splashView;
            UIView *containerView = extra[kATSplashExtraContainerViewKey];
            self->_customEvent.containerView = containerView;
            
            [self->_splashView loadAdData];
        });
    } else {
        completion(nil, [NSError errorWithDomain:ATADLoadingErrorDomain code:ATADLoadingErrorCodeThirdPartySDKNotImportedProperly userInfo:@{NSLocalizedDescriptionKey:@"AT has failed to load splash.", NSLocalizedFailureReasonErrorKey:@"It took too long to load placement stragety."}]);
    }
}

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


+ (void)showSplash:(ATSplash *)splash localInfo:(NSDictionary *)localInfo delegate:(id<ATSplashDelegate>)delegate {
    BUSplashAdView *splashView = splash.customObject;
    ATTTSplashCustomEvent *customEvent = (TouTiaoSplashCustomEvent *)splashView.delegate;
    
    // Here you can get the window passed in by the developer when they show ad.
    UIWindow *window = localInfo[kATSplashExtraWindowKey];
    customEvent.backgroundImageView = localInfo[kATSplashExtraBackgroundImageViewKey];
    [window addSubview:customEvent.containerView];
    [window addSubview:customEvent.ttSplashView];
}

2.2 Implement the CustomEvent class for advertising callback

You need to customize a xxxCustomEvent class, inherit the ATSplashCustomEvent 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 corresponding event method of calling ATSplashCustomEvent is passed back to the TopOn SDK.

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

Create and implement the TouTiaoSplashCustomEvent class:

@interface ATTTSplashCustomEvent : ATSplashCustomEvent<BUSplashAdDelegate>

@property(nonatomic) NSDate *expireDate;
@end

- (void)splashAdDidLoad:(BUSplashAdView *)splashAd {
    if ([[NSDate date] timeIntervalSinceDate:_expireDate] > 0) {
        NSError *error = [NSError errorWithDomain:ATADLoadingErrorDomain code:ATADLoadingErrorCodeADOfferLoadingFailed userInfo:@{NSLocalizedDescriptionKey:@"AT has failed to load splash.", NSLocalizedFailureReasonErrorKey:@"It took too long for TT to load splash."}];
        [_backgroundImageView removeFromSuperview];
        [self trackSplashAdLoadFailed:error];
    } else {
        [_window addSubview:_containerView];
        [_window addSubview:_ttSplashView];
        [self trackSplashAdLoaded:splashAd adExtra:nil];
    }
}

- (void)splashAd:(BUSplashAdView *)splashAd didFailWithError:(NSError *)error {
    [_backgroundImageView removeFromSuperview];
    [_ttSplashView removeFromSuperview];
    [_containerView removeFromSuperview];
    [self trackSplashAdLoadFailed:error];
}

- (void)splashAdDidClick:(BUSplashAdView *)splashAd {
    [self trackSplashAdClick];
}

- (void)splashAdDidClose:(BUSplashAdView *)splashAd {
    [_containerView removeFromSuperview];
    [_backgroundImageView removeFromSuperview];
    [(UIView*)splashAd removeFromSuperview];
    [self trackSplashAdClosed];
}

- (void)splashAdWillClose:(BUSplashAdView *)splashAd {
}

- (void)splashAdWillVisible:(BUSplashAdView *)splashAd {
    [self trackSplashAdShow];
}

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


Previous
Interstitials
Next
Banner ads
Last modified: 2025-05-30Powered by