1. Create a custom Banner Adapter class that can inherit NSObject. And follow the ATAdAdapter protocol, it is recommended to end with BannerAdapter, 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 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 a 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 |
+(void) showBanner:(ATBanner* )banner inView:(UIView* )view presentingViewController:(UIViewController* )viewController; | banner: Custom advertising banner object view : BannerView container defined inside topon sdk viewController: Current view controller | void | Used to handle when the bannerAdView object is not returned in the successful callback of the advertising platform, you can use this method to add bannerView | No |
3. The callback method is described as follows: You need to customize a xxxCustomEvent class , inherit the ATBannerCustomEvent 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 ATBannerCustomEvent for the corresponding event is passed back to the TopOn SDK.
The specific callback method is described as follows:
Callback method | Parameter description | Description |
---|---|---|
-(void) trackBannerAdLoaded:(id)bannerView adExtra:(NSDictionary * )adExtra | bannerView: bannerView object adExtra: extended information | Execute a callback to the developer when the ad is loaded successfully |
-(void) trackBannerAdLoadFailed:(NSError* )error | error: error message | Execute a callback to the developer when the ad loading fails |
-(void ) trackBannerAdClick | - | The ad was clicked Callback to the developer when executed |
-(void) trackBannerAdClosed -(void) bannerView:(ATBannerView* )bannerView didTapCloseButtonWithPlacementID:(NSString* )placementID extra:(NSDictionary* )extra | bannerView: bannerView object placementID: advertising slot id extra: specific information of the advertising source | Execute a callback to the developer when the ad is clicked off |
1. Create a custom Banner Adapter class, which can inherit NSObject. It is recommended to end with BannerAdapter. 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 TouTiaoBannerCustomAdapter class:
//TouTiaoBannerCustomAdapter.m
#import <AnyThinkBanner/AnyThinkBanner.h>
@interface TouTiaoBannerCustomAdapter()<ATAdAdapter>
@property(nonatomic, readonly) TouTiaoBannerCustomEvent *customEvent;
@end
@implementation TouTiaoBannerCustomAdapter
/// 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 *extraInfo = localInfo;
CGSize adSize = [extraInfo[kATAdLoadingExtraBannerAdSizeKey] respondsToSelector:@selector(CGSizeValue)] ? [extraInfo[kATAdLoadingExtraBannerAdSizeKey] CGSizeValue] : CGSizeMake(320.0f, 50.0f);
_customEvent = [[TouTiaoBannerCustomEvent alloc] initWithInfo:serverInfo localInfo:localInfo];
_customEvent.requestCompletionBlock = completion;
dispatch_async(dispatch_get_main_queue(), ^{
BUSize *size = [BUSize sizeBy:[serverInfo[@"media_size"] integerValue]];
self->_bannerView = [[BUNativeExpressBannerView alloc] initWithSlotID:serverInfo[@"slot_id"] rootViewController:[ATBannerCustomEvent rootViewControllerWithPlacementID:((ATPlacementModel*)serverInfo[kAdapterCustomInfoPlacementModelKey]).placementID requestID:serverInfo[kAdapterCustomInfoRequestIDKey]]
adSize:CGSizeMake(adSize.width, adSize.width * size.height / size.width) IsSupportDeepLink:YES ];
self->_bannerView.frame = CGRectMake(.0f, .0f, adSize.width, adSize.width * size.height / size.width);
self->_bannerView.delegate = self->_customEvent;
[self->_bannerView loadAdData];
});
}
+(void) showBanner:(ATBanner*)banner inView:(UIView*)view presentingViewController:(UIViewController*)viewController {
ALAdView *bannerView = banner.bannerView;
[bannerView render:banner.customObject];
}
You need to customize a xxxCustomEvent class, inherit the ATBannerCustomEvent class, and add a callback agent corresponding to the screen opening of the custom advertising platform through this class. When the advertising platform has a callback, Pass the corresponding event method called ATBannerCustomEvent back to TopOn SDK.
The following is an integration example. For specific projects, please refer to demo:
Create and implement the TouTiaoBannerCustomEvent class:
The following is an example of pangolin Banner ad callback:
- (void)nativeExpressBannerAdViewDidLoad:(BUNativeExpressBannerView *)bannerAdView {
NSLog(@"TouTiaoBannerCustomEvent::bannerAdViewDidLoad:WithAdmodel:");
[self trackBannerAdLoaded:bannerAdView adExtra:nil];
}
- (void)nativeExpressBannerAdViewWillBecomVisible:(BUNativeExpressBannerView *)bannerAdView {
NSLog(@"TouTiaoBannerCustomEvent::bannerAdViewDidBecomVisible:WithAdmodel:");
}
- (void)nativeExpressBannerAdViewDidClick:(BUNativeExpressBannerView *)bannerAdView {
NSLog(@"TouTiaoBannerCustomEvent::bannerAdViewDidClick:WithAdmodel:");
[self trackBannerAdClick];
}
- (void)nativeExpressBannerAdView:(BUNativeExpressBannerView *)bannerAdView didLoadFailWithError:(NSError *_Nullable)error {
NSLog(@"%@",[NSString stringWithFormat:@"TouTiaoBannerCustomEvent::bannerAdView:didLoadFailWithError:%@",error]);
[self handleLoadingFailure:error];
}
- (void)nativeExpressBannerAdView:(BUNativeExpressBannerView *)bannerAdView dislikeWithReason:(NSArray<BUDislikeWords *> *_Nullable)filterwords {
NSLog(@"TouTiaoBannerCustomEvent::bannerAdView:dislikeWithReason:");
// [self.bannerView loadNextWithoutRefresh];
if ([self.delegate respondsToSelector:@selector(bannerView:didTapCloseButtonWithPlacementID:extra:)]) {
[self.delegate bannerView:self.bannerView didTapCloseButtonWithPlacementID:self.banner.placementModel.placementID extra:[self delegateExtra]];
}
[self trackBannerAdClosed];
}
- (NSString *)networkUnitId {
return self.serverInfo[@"slot_id"];
}