Asynchronous Infeed Banner
This placement requires iOS 13 and above.
Asynchronous Infeed banner placements wrap the Infeed banner placement providing the same functionality but supporting Swift Concurrency.
Create Placement
To create an instance of AATAsyncInfeedBannerPlacement, use the following API:
let configuration = AATBannerConfiguration()
let placement = AATSDK.createAsyncInfeedBannerPlacement(name: "<PLACEMENT_NAME>", configuration: configuration)
AATBannerConfiguration *configuration = [[AATBannerConfiguration alloc] init];
id <AATAsyncInfeedBannerPlacement> bannerPlacement = [AATSDK createAsyncInfeedBannerPlacement:@"<PLACEMENT_NAME>" configuration:configuration];
AATBannerConfiguration
See the infeed banner configuration documentation.
Listen to Callbacks (Optional)
See the infeed callbacks documentation.
Request Ad
The async infeed banner placement uses swift concurrency. To request a banner, use the AATBannerRequest default initializer that takes an instance implementing AATBannerRequestDelegate as a parameter.
Configure AATBannerRequest
See the infeed banner request configuration.
Perform Request
You can request multiple AATBannerRequest
in parallel (i.e. the next one, before the previous one was completed).
Task {
let request = AATBannerRequest(delegate: self)
guard let adView = await bannerPlacement?.requestAd(request: request) else {
return
}
// Display the adView
}
AATBannerRequest *request = [[AATBannerRequest alloc] initWithDelegate:self];
[self.bannerPlacement requestAdWithRequest:request
completion:^(AATBannerPlacementWrapperView * _Nullable bannerView, AATBannerRequestError * _Nullable error) {
if (error) {
// Handle Error
return;
}
// Handle banner display
}];
Complete Code Example
class ViewController: UIViewController {
// Create the placement
var placement: AATInfeedBannerPlacement?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// [IMPORTANT] Notify AATKit about the currently active view controller
AATSDK.controllerViewDidAppear(controller: self)
let configuration = AATBannerConfiguration()
placement = AATSDK.createInfeedBannerPlacement(name: "<PLACEMENT_NAME>", configuration: configuration)
// Set placement delegate to listen to the callbacks
placement.delegate = self
// Create the banner request instance
let request = AATBannerRequest(delegate: self)
// Configure request banner sizes
request.setRequestBannerSizes(sizes: Set([.banner320x53, .banner300x250]))
// Configure request targeting information
request.contentTargetingUrl = "http://example.com/similar/content"
// Configure request content targeting URL
request.targetingInformation = ["key": ["value"]]
// Perform the request
Task {
let request = AATBannerRequest(delegate: self)
guard let adView = await bannerPlacement?.requestAd(request: request) else {
return
}
// Display the adView
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// [IMPORTANT] Remove the currently active view controller
AATSDK.controllerViewWillDisappear()
}
}
// MARK: AATInfeedBannerPlacementDelegate
extension ViewController: AATInfeedBannerPlacementDelegate {
func aatPauseForAd(placement: AATPlacement) {
// Ad has been displayed on the screen
}
func aatResumeAfterAd(placement: AATPlacement) {
// Back to the app after clicking on the ad
}
}
// MARK: AATBannerRequestDelegate
extension ViewController: AATBannerRequestDelegate {
func shouldUseTargeting(for request: AATBannerRequest, network: AATAdNetwork) -> Bool {
return true
}
}
@interface ViewController () <AATInfeedBannerPlacementDelegate, AATBannerRequestDelegate>
@property id<AATAsyncInfeedBannerPlacement> placement;
@end
@implementation ViewController
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// [IMPORTANT] Notify AATKit about the currently active view controller
[AATSDK controllerViewDidAppearWithController:self];
// Create the placement
AATBannerConfiguration *configuration = [[AATBannerConfiguration alloc] init];
return [AATSDK createAsyncInfeedBannerPlacement:@"<PLACEMENT_NAME>" configuration:configuration];
// Set placement delegate to listen to the callbacks
self.placement.delegate = self;
// Create the banner request instance
AATBannerRequest *request = [[AATBannerRequest alloc] initWithDelegate:self];
// Configure request banner sizes
NSSet *sizes = [[NSSet alloc] initWithArray:@[@(AATBannerSizeBanner320x53), @(AATBannerSizeBanner300x250), @(AATBannerSizeBanner320x100)]];
[request setRequestBannerSizes: sizes];
// Configure request targeting information
request.targetingInformation = @{@"Key": @[@"value"]};
// Configure request content targeting URL
request.contentTargetingUrl = @"http://example.com/similar/content";
// Perform the request
[self.placement requestAdWithRequest: request
completion:^(AATBannerPlacementWrapperView * _Nullable bannerView, AATBannerRequestError * _Nullable error) {
if (error) {
// Handle Error
return;
}
// Handle banner display
}];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// [IMPORTANT] Remove the currently active view controller
[AATSDK controllerViewWillDisappear];
}
#pragma mark - AATInfeedBannerPlacementDelegate
- (void)aatPauseForAdWithPlacement:(id<AATPlacement> _Nonnull)placement {
// Ad has been displayed on the screen
}
- (void)aatResumeAfterAdWithPlacement:(id<AATPlacement>)placement {
// Back to the app after clicking on the ad
}
#pragma mark - AATBannerRequestDelegate
- (BOOL)shouldUseTargetingFor:(AATBannerRequest * _Nonnull)request network:(enum AATAdNetwork)network {
return YES;
}
@end
Last updated