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 loading open-screen ads on the custom advertising platform. | 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 open-screen advertisement of the custom advertising platform is ready | Yes |
+ (void)showSplash:(ATSplash *)splash localInfo:(NSDictionary *)localInfo delegate:(id)delegate | splash: 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 | void | Implement the logic of displaying open-screen ads on a custom advertising platform. Note that this is a class method | Yes 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 method | Parameter description | Description |
---|---|---|
-(void) trackSplashAdLoaded:(id)splashAd adExtra:(NSDictionary *)adExtra | splashAd: advertising object adExtra: extended information | Execute a callback to TopOn SDK when the ad is loaded successfully |
-(void) trackSplashAdLoadFailed:(NSError*)error | error: error message | Execute 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)countdown | countdown: current countdown time | Implements custom buttons and countdown related parameters. After the countdown starts, call back the current countdown time to TopOn SDK |
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:
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];
}
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"];
}