Wiki

Clone wiki

Banner Sample / AATKit 3 banner cache migration

Banner Cache

Index:

  1. Banner Cache
  2. Usage Example
  3. Configuring the ad request
  4. Sample App

Banner Cache

AATKit supports BannerCache - a special tool to help you integrate in-feed banners. It will automatically preload banner ads and try to have a defined amount of banners available for immediate handout to the app whenever they are needed.

Constructor: - (instancetype)initWithConfiguration:(AATBannerCacheConfiguration *) configuration where:

configuration - The configuration object that contains all needed configurations.

AATBannerCacheConfiguration object:

Instead of the following 2 constructors:

- (instancetype)initWithConfiguration:(AATBannerCacheConfiguration *)configuration

- (instancetype)initWithConfiguration:(AATBannerCacheConfiguration *)configuration andStatisticsDelegate:(nullable NSObject <AATStatisticsDelegate>*)statisticsDelegate

Use one of the following:

@objc public convenience init(cacheConfiguration: AATBannerCacheConfiguration)

@objc public init(cacheConfiguration: AATBannerCacheConfiguration, statisticsListener: AATStatisticsDelegate?)

AATBannerCacheConfiguration has the following variables to customise the AATBannerCache:

placementName - The name of the banner placement that will be created. The placement will be created by the cache and should not be created manually. size - Defines how many preloaded banners should be available in the cache. Max value: 5 AATBannerCacheDelegate - Optional cache delegate that will be called when the first banner ad gets loaded. Can be null. It will be notified when the first banner is loaded and ready to be consumed. shouldCacheAdditionalAdAtStart - A BOOL defines if the cache should load additional ad at the beginning. False by default. requestConfiguration - AATBannerRequest with configurations. minDelay - NSTimeInterval minimum delay between two banner consumptions.

Consume Banners

Both AATKit 2.x.x and 3.x.x use the same consume API:

- (nullable UIView *)consume - returns an instance of UIView to be used within the app. Can return nil if there are no banners available in the cache. Also automatically counts an ad space. BannerCache will no longer hold any references to returned banners, and they need to be destroyed manually by the app.

In addition to the standard consume() method, additional one: - (nullable UIView *)consume:(BOOL) forceConsume;, allowing to consume banners ignoring the minimum delay set in BannerCacheConfiguration is available

Both AATKit 2.x.x and 3.x.x use the same destroy method:

- (void)destroy - Destroys the BannerCache, clearing all preloaded banner ads and canceling pending reload requests. For proper memory management, it needs to be called when the BannerCache is no longer needed. Destroyed BannerCache can no longer be used.

Optional methods

  • Update request configurations:

Instead of:

- (void)updateRequestConfiguration:(AATAdRequest *)adRequest shouldRefresh:(BOOL)shouldRefresh - updates the configuration that will be used when requesting new banners.

adRequest - new AATAdRequest configuration, can not be null

shouldRefresh - true if the whole cache should be re-loaded with new banner request configuration, false if new configuration should only be used for new requests.

- (void)setCacheDelegate:(nullable id<AATBannerCacheDelegate>)delegate - sets the optional CacheDelegate.

Use:

func updateRequestConfiguration(_ requestConfiguration: AATBannerRequest, shouldRefresh: Bool) - updates the configuration that will be used when requesting new banners.

requestConfiguration - new AATBannerRequest configuration, can not be null

shouldRefresh - true if the whole cache should be re-loaded with new banner request configuration, false if new configuration should only be used for new requests.

Configuring the ad request

You may configure the requested banner sizes, add keyword targeting, a content targeting url or a delegate to the ad request.

Instead of:

Objective-C:

#!objective-c
AATAdRequest* adRequest = [[AATAdRequest alloc] initWithDelegate:self viewController:self];
adRequest.bannerSizes = [[NSSet alloc] initWithArray:@[@(AATKitBanner320x53), @(AATKitBanner300x250)]];
adRequest.targetingKeywords = @{@"news-category" : @"technology"};
adRequest.contentTargetingURL = [NSURL URLWithString:@"http://example.com/similar/content"];
adRequest.delegate = self;
Swift:
#!swift
let adRequest = AATAdRequest(delegate: self, viewController: self)
adRequest.bannerSizes = [NSNumber(value: AATKitAdType.banner320x53.rawValue), NSNumber(value: AATKitAdType.banner300x250.rawValue)]
adRequest.targetingKeywords["news-category"] = NSString(string: "technology")
adRequest.contentTargetingURL = URL(string: "http://example.com/similar/content")

Use:

Objective-C:

AATBannerRequest *request = [[AATBannerRequest alloc] initWithDelegate:self];
NSSet *sizes = [[NSSet alloc] initWithArray:@[@(AATBannerSizeBanner320x53), @(AATBannerSizeBanner300x250), @(AATBannerSizeBanner320x100)]];
[request setRequestBannerSizes:sizes];
request.contentTargetingUrl = @"http://example.com/similar/content";
request.targetingInformation = @{@"Key": @[@"value"]};

Swift:

let request = AATBannerRequest(delegate: self)
request.contentTargetingUrl = "http://example.com/similar/content"
request.targetingInformation = ["key": ["value"]]
request.setRequestBannerSizes(sizes: Set(arrayLiteral: .banner320x53, .banner300x250))

Sample App

Updated