Wiki

Clone wiki

AATKit iOS / Proposal / BannerInfeed2

Infeed Banner

  1. Getting Started
  2. AATKit Initialisation
  3. Banners
  4. Consent Handling
  5. Formats
  6. Targeting
  7. Advanced

Infeed Banner

Create Infeed Banner

In order to use the banner placement, you need to create one. This is very similar to the code that you could use before, there is just a small variation with the updated protocol type and the new factory method

Objective-C:

//  call this to get an already created placement
id bannerPlacement = [AATKit getPlacementWithName:@"banner_name"];
// call this to create a new placement
id bannerPlacement = [AATKit createBannerPlacementWithName:@"banner_name"];

Swift:

//  call this to get an already created placement
AATKit.getPlacementWithName(placementName) 
// call this to create a new placement
AATKit.createBannerPlacement(name: placementName) 

so you can have someething like that in your ViewController Swift:*

   var inFeedBannerPlacement: AATBannerPlacementProtocol {
        get {
            let placementName = <<PlacementName>>
            guard let placement = AATKit.getPlacementWithName(placementName) as? AATBannerPlacementProtocol else {
              return AATKit.createBannerPlacement(name: placementName)
            }
            return placement
        }
    }

Create an Ad Request

to request Ad you need to initialize an AATAdRequest object with the configuration you need.

note you can request multiple AdRequest in parallel

Objective-C:

AATAdRequest* adRequest = [[AATAdRequest alloc] initWithViewController:self];
adRequest.bannerSizes = [[NSSet alloc] initWithArray:@[@(AATKitBanner320x53), @(AATKitBanner300x250)]];
[inFeedBannerPlacement executeRequest:adRequest completionHandler:^(UIView * _Nullable bannerView, NSError * _Nullable error) {
    [pendingRequests removeObject:adRequest];

    if (error) {
        //Handle Error
        return;
    }

    //Insert the adView into view hierarchy
}];

Swift:

let adRequest = AATAdRequest(viewController: self)
adRequest.bannerSizes = [NSNumber(value: AATKitAdType.banner320x53.rawValue), NSNumber(value: AATKitAdType. banner300x250.rawValue)]
inFeedBannerPlacement.execute(adRequest) { [weak self] (adView, error) in
    guard error == nil else {
        //Handle Error
        return
    }
    //Insert the adView into view hierarchy
}

Configuring AATAdRequest

AATAdRequest can be configured with the requested banner sizes, add keyword targeting, a content targeting url or a delegate to the ad reque

Objective-C:

AATAdRequest* adRequest = [[AATAdRequest alloc] initWithViewController:self];
adRequest.bannerSizes = [[NSSet alloc] initWithArray:@[@(AATKitBanner320x53), @(AATKitBanner300x250)]];
adRequest.targetingKeywords = @{@"news-category" : @"technology"};
adRequest.contentTargetingURL = @"http://example.com/similar/content";
adRequest.delegate = self;

Swift:

let adRequest = AATAdRequest(viewController: self)
adRequest.bannerSizes = [NSNumber(value: AATKitAdType.banner320x53.rawValue), NSNumber(value: AATKitAdType.banner300x250.rawValue)]
adRequest.targetingKeywords["news-category"] = NSString(string: "technology")
adRequest.contentTargetingURL = "http://example.com/similar/content"
adRequest.delegate = self

Cancelling a Request

There might be pending ad request when the user navigates to a different view controller. To keep the existing life-cycle of the view controller, you need to cancel any pending requests

Objective-C:

[inFeedBannerPlacement cancelRequest:request];
Swift:
inFeedBannerPlacement?.cancel(adRequest)

Assign a specific view controller to a placement

Passing the ViewController to the AATKit v3.x.x:

  • To pass the proper ViewController to AATKit, you should follow the following in the viewWillAppear method:

Objective-C:

[AATSDK controllerViewWillAppearWithController:self];
Swift:
#!swift
AATSDK.controllerViewWillAppear(controller: self)
* In the ViewController's viewWillDisappear method, you should do the following:

Objective-C:

[AATSDK controllerViewWillDisappear];
Swift:
#!swift
AATSDK.controllerViewWillDisappear()

AppNexus add native banners support

You can add AppNexus native banners support by adding the key AATKitAppNexusNativeBanner to your Info.plist and set the value to true

Listening to statistics events

AATKitStatisticsDelegate is an optional delegate you can implement if you need to get notified about statistics events. and pass it to placement while creating it using this method

+ (nullable NSObject<AATKitPlacement>*) createPlacementWithName:(nonnull NSString *) placementName
                                                        andType:(AATKitAdType)type
                                          andStatisticsDelegate:(nullable NSObject <AATKitStatisticsDelegate>*)statisticsDelegate

Updating statistics delegate instance

You can pass a new statistics delegate instance to the placement by using the following method in AATBannerPlacementProtocol:

- (void)updateStatisticsDelegate:(nonnull NSObject <AATKitStatisticsDelegate> *)statisticsDelegate;

for more info about it please refer to AATKitStatisticsDelegate Guide

Sample App

back (Home)

Updated