Banner ads

A banner is a configurable ad that covers part of the screen and reacts to clicks.

To enable the banner:

  1. Add the import:

    #import <YandexMobileAds/YandexMobileAds.h>
  2. Create @property, where the link to the banner ad will be stored:

    @property (nonatomic, strong) YMAAdView *adView;
  3. Specify the banner size and initialize the banner in the app:

    self.adView = [[YMAAdView alloc] initWithBlockID:<your unique BlockID>];
    adSize:<Size of the YMAAdSize class> delegate:self];
    Restriction. Requirements for banner size when displaying video ads

    Minimum size of a banner that supports video playback is 300x160 or 160x300.

    Block ID is a unique identifier in the adf-XXXXXX/YYYYYY format, which is assigned in the Partner interface.
    Attention.

    In the mobile mediation interface, the Block ID is called the location ID.

    In addition, self must conform to the YMAAdViewDelegate protocol. If the delegate implements the - (UIViewController *)viewControllerForPresentingModalView method, links open in the in-app browser. Otherwise, links open in the browser installed on the device.

    To determine why advertising is not working correctly, use the - (void)adViewDidFailLoading:(YMAAdView *)adView error:(NSError *)error method.

    For error descriptions, see YMAAdErrorCode.

  4. Display a banner. There are two ways to place a banner:

    • Using autolayout constraints. To place the banner, add it to UIView:
       [self.view addSubview:self.adView];

      Then add autolayout constraints so the banner is displayed in the desired location. In the example below, two autolayout constraints are added — vertical centering and horizontal centering.

      [self.adView setTranslatesAutoresizingMaskIntoConstraints:NO];
       NSLayoutConstraint *centerHorizontally =
          [NSLayoutConstraint constraintWithItem:self.adView
                                       attribute:NSLayoutAttributeCenterX
                                       relatedBy:NSLayoutRelationEqual
                                          toItem:self.view
                                       attribute:NSLayoutAttributeCenterX
                                      multiplier:1.f
                                        constant:0.f];
      NSLayoutConstraint *centerVertically =
          [NSLayoutConstraint constraintWithItem:self.adView
                                       attribute:NSLayoutAttributeCenterY
                                       relatedBy:NSLayoutRelationEqual
                                          toItem:self.view
                                       attribute:NSLayoutAttributeCenterY
                                      multiplier:1.f
                                        constant:0.f];
      
      [self.view addConstraint:centerVertically];
      [self.view addConstraint:centerHorizontally];
    • Using the following methods:

      - (void)displayAtTopInView:(UIView *)view;
      - (void)displayAtBottomInView:(UIView *)view;

      In both cases, banners are centered horizontally.

  5. Load the banner. Optionally, you can use the YMAAdRequest class to transmit the data for targeting.

    - (void)loadAdWithRequest:(YMAAdRequest *)request;

    When the banner loads, the delegate is notified.

  6. Optionally, you can set up notifications about the end of video playback in banner ads.
    Usage example
    //  Getting an instance of  YMAVideoController using videoController.
    YMAVideoController *videoController = self.adView.videoController;
    
    // Sets up a delegate that implements the YMAVideoDelegate protocol.
    videoController.delegate = self;
    
    // Implements the YMAVideoDelegate protocol method.
    #pragma mark - YMAVideoDelegate
    - (void)videoControllerDidFinishPlayingVideo:(YMAVideoController *)videoController
    {
        NSLog(@"%@", @"Video complete");
    }