# Asynchronous Infeed Banner

{% hint style="info" %}
This placement requires iOS 13 and above.
{% endhint %}

Asynchronous Infeed banner placements wrap the [Infeed banner placement](/ios-integration/formats/banner/infeed-banner.md) providing the same functionality but supporting Swift Concurrency.

### Create Placement

To create an instance of [AATAsyncInfeedBannerPlacement](https://ios-sdk.aatkit.com/references/documentation/aatkit/aatasyncinfeedbannerplacement), use the following API:

{% tabs %}
{% tab title="Swift" %}

```swift
let configuration = AATBannerConfiguration()
let placement = AATSDK.createAsyncInfeedBannerPlacement(name: "<PLACEMENT_NAME>", configuration: configuration)
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
AATBannerConfiguration *configuration = [[AATBannerConfiguration alloc] init];
id <AATAsyncInfeedBannerPlacement> bannerPlacement = [AATSDK createAsyncInfeedBannerPlacement:@"<PLACEMENT_NAME>" configuration:configuration];
```

{% endtab %}
{% endtabs %}

#### **AATBannerConfiguration**

See the infeed [banner configuration documentation](/ios-integration/formats/banner/infeed-banner.md#aatbannerconfiguration).

### Listen to Callbacks (Optional)

See the [infeed callbacks documentation](/ios-integration/formats/banner/infeed-banner.md#listen-to-callbacks-optional).

### Request Ad

The async infeed banner placement uses swift concurrency. To request a banner, use the [AATBannerRequest](https://ios-sdk.aatkit.com/references/documentation/aatkit/aatbannerrequest) default initializer that takes an instance implementing [AATBannerRequestDelegate](https://ios-sdk.aatkit.com/references/documentation/aatkit/aatbannerrequestdelegate) as a parameter.

#### **Configure AATBannerRequest**

See the [infeed banner request configuration](/ios-integration/formats/banner/infeed-banner.md#configure-aatbannerrequest).

#### **Perform Request**

{% hint style="info" %}
You can request multiple `AATBannerRequest` in parallel (i.e. the next one, before the previous one was completed).
{% endhint %}

{% tabs %}
{% tab title="Swift" %}

```swift
Task {
    let request = AATBannerRequest(delegate: self)
    guard let adView = await bannerPlacement?.requestAd(request: request) else {
        return
    }
    // Display the adView
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
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
}];
```

{% endtab %}
{% endtabs %}

### Complete Code Example

{% tabs %}
{% tab title="Swift" %}

```swift
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
	}
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
@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
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aatkit.gitbook.io/ios-integration/formats/banner/asynchronous-infeed-banner.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
