# Multi-Size Banner

{% hint style="info" %}
This placement type is deprecated. We recommend using the new [multi-size-auto-load-banner](https://aatkit.gitbook.io/ios-integration/formats/banner/multi-size-auto-load-banner "mention") type instead.
{% endhint %}

Multi-size banner placements are similar to [sticky banners](https://aatkit.gitbook.io/ios-integration/formats/banner/sticky-banner), but can present banners of varying sizes. For instance, it is possible to display a banner of the standard size 320x53, followed by a medium rectangle of size 300x250 within the same placement.

### Create Placement <a href="#create-placement" id="create-placement"></a>

It will depend on the server-side configuration on the Dashboard and what actual sizes are getting delivered to your placement.

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

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

```swift
var placement = AATSDK.createMultiSizeBannerPlacement(name: "<PLACEMENT_NAME>")
```

{% endtab %}

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

```objectivec
id<AATMultiSizeBannerPlacement> placement = [AATSDK createMultiSizeBannerPlacementWithName:@"<PLACEMENT_NAME>"];
```

{% endtab %}
{% endtabs %}

<figure><img src="https://3006681101-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC07HayBzqyav5R2yFhOr%2Fuploads%2FDW7LXxzi62jK428fFrYq%2FMulti1.png?alt=media&#x26;token=b85c588c-0227-4aec-91b3-f37ac2354370" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The green background is an ad container (UIView), into which the placement view is added by the app. It represents the space that the app reserves for a multi-size banner placement view (the green colour is just used here for explanatory purposes).
{% endhint %}

### Listen to Callbacks <a href="#listen-to-callbacks-optional" id="listen-to-callbacks-optional"></a>

Through the use of [AATMultiSizeBannerPlacementDelegate](https://ios-sdk.aatkit.com/references/documentation/aatkit/aatmultisizebannerplacementdelegate), you can listen to the different placement callbacks.

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

```swift
placement.delegate = self
```

{% endtab %}

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

```objectivec
placement.delegate = self;
```

{% endtab %}
{% endtabs %}

### Request Ad

#### Automatic Reload <a href="#automatic-reload" id="automatic-reload"></a>

To automatically load (and reload) the sticky banner placement enable auto-reload. If you do not set the refresh time interval seconds explicitly, AATKit will

* Reload every 30 seconds (if no refresh time interval is set on the Dashboard)
* Respect the refresh time interval setting of the Dashboard (which means, you can configure the interval without having to re-publish your app)

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

```swift
// reload the banner placement every 30 seconds.
placement.startAutoReload()
// OR set refresh time manually
placement.startAutoReload(seconds: 45)
```

{% endtab %}

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

```objectivec
//reload the banner placement every 30 seconds.
[self.placement startAutoReload];
// or set refresh time manually
[self.placement startAutoReloadWithSeconds:45];
```

{% endtab %}
{% endtabs %}

The minimum refresh time is 30 seconds.

This needs to stop the auto-reload when it is no longer needed (e.g. if the view controller presenting ads will disappear):

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

```swift
placement.stopAutoReload()
```

{% endtab %}

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

```objectivec
[self.placement stopAutoReload];
```

{% endtab %}
{% endtabs %}

#### Manual Load <a href="#manual-load" id="manual-load"></a>

To manually load the sticky banner placement:

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

```swift
placement.reload()
// Or using force load
placement.reload(forceLoad: true)
```

{% endtab %}

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

```objectivec
[placement reload];
// Or using force load
[self.placement reloadWithForceLoad:YES];
```

{% endtab %}
{% endtabs %}

**Force Load**

* `false` (default): `reload()` will respect the current time interval.
* `true`: `reload()` will immediately reload (irrespective of the fact when the last ad was loaded). This can be useful if the same sticky banner placement is used on various different pages of the app and you want to load a new ad every time the user navigates to another page (while still using auto-reloading).

### Complete Code Example <a href="#complete-code-example" id="complete-code-example"></a>

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

```swift
class ViewController: UIViewController {
    // Create the placement
    var placement = AATSDK.createMultiSizeBannerPlacement(name: "<PLACEMENT_NAME>")
    var bannerAdView: UIView?
 
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        // [IMPORTANT] Notify AATKit about the currently active view controller
        AATSDK.controllerViewDidAppear(controller: self)
        
        // Set placement delegate to listen to the callbacks
        placement.delegate = self
        
        // reload the banner placement every 30 seconds.
        placement.startAutoReload()
        // OR set refresh time manually
        placement.startAutoReload(seconds: 30)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        // [IMPORTANT] Remove the currently active view controller
        AATSDK.controllerViewWillDisappear()
        // [IMPORTANT] Stop placement auto-reload
        placement?.stopAutoReload()
    }
}

extension ViewController: AATMultiSizeBannerPlacementDelegate {
    func aatHaveAdWithBannerView(placement: AATPlacement, bannerView: AATBannerPlacementWrapperView) {
        // The placement has loaded a new ad
        // [IMPORTANT] remove the previously displayed banner view
        bannerAdView?.removeFromSuperview()
        bannerAdView = bannerView
        view.addSubview(bannerAdView)
        // Change bannerView frame (or constraints) to the desired location on the screen
    }

    func aatNoAd(placement: AATPlacement) {
        // The placement could not load a new ad
    }
    
    func aatPauseForAd(placement: AATPlacement) {
        // Ad has been displayed on the screen
    }

    func aatResumeAfterAd(placement: AATPlacement) {
        // Back to the app after clicking on the ad
    }
}
```

{% endtab %}

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

```objectivec
@interface ViewController () <AATMultiSizeBannerPlacementDelegate>
@property id<AATMultiSizeBannerPlacement> placement;
@property UIView *bannerAdView;
@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
    self.placement = [AATSDK createMultiSizeBannerPlacementWithName:@"<PLACEMENT_NAME>"];
    
    // Set placement delegate to listen to the callbacks
    self.placement.delegate = self;
    
    //reload the banner placement every 30 seconds.
    [self.placement startAutoReload];
    // or set refresh time manually
    [self.placement startAutoReloadWithSeconds:30];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    // [IMPORTANT] Remove the currently active view controller
    [AATSDK controllerViewWillDisappear];
    // [IMPORTANT] Stop placement autoreload
    [self.placement stopAutoReload];
}

#pragma mark - AATMultiSizeBannerPlacementDelegate
- (void)aatHaveAdWithBannerViewWithPlacement:(id<AATPlacement> _Nonnull)placement bannerView:(AATBannerPlacementWrapperView * _Nonnull)bannerView {
    // The placement has loaded a new ad
    // [IMPORTANT] remove the previously displayed banner view
    [self.bannerAdView removeFromSuperview];
    self.bannerAdView = bannerView;
    [self.view addSubview:self.bannerAdView];
    // Change bannerAdView frame (or constraints) to the desired location on the screen
}

- (void)aatNoAdWithPlacement:(id<AATPlacement> _Nonnull)placement {
    // The placement could not load a new ad
}

- (void)aatPauseForAdWithPlacement:(id<AATPlacement> _Nonnull)placement {
    // Ad has been displayed on the screen
}

- (void)aatResumeAfterAdWithPlacement:(id<AATPlacement> _Nonnull)placement { 
    // Back to the app after clicking on the ad
}
@end
```

{% endtab %}
{% endtabs %}
