Menu

Banner ads

1. Main development work instructions

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:

  • 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 a custom ad source needs to be displayed When advertising, the showBanner: method call will be triggered.

The specific method is as follows:

Abstract 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 a custom adapter Yes
-(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
+(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
voidUsed to handle when the bannerAdView object is not returned in the successful callback of the advertising platform, you can use this method to add bannerViewNo

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 methodParameter descriptionDescription
-(void) trackBannerAdLoaded:(id)bannerView adExtra:(NSDictionary * )adExtrabannerView: bannerView object
adExtra: extended information
Execute a callback to the developer when the ad is loaded successfully
-(void) trackBannerAdLoadFailed:(NSError* )errorerror: error messageExecute 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

2. Specific integration instructions and examples

2.1 Adapter to implement advertising loading Class

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:

  • Implement initWithNetworkCustomInfo: instance Adapter object, you can perform relevant initialization of the advertising SDK here.
  • Implement the loadADWithInfo: method called when advertising is loaded to trigger the advertising request of the advertising SDK.
  • Implement the adReadyWithCustomObject: method to inform TopOn SDK whether there are currently ads to fill.
  • •Implement the showBanner: 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 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];
}

2.2 CustomEvent class that implements advertising callback

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


Previous
Splash ads
Next
native advertising
Last modified: 2025-05-30Powered by