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:

    YMAAdSize *adSize = [YMAAdSize flexibleSizeWithContainerWidth:CGRectGetWidth(self.view.frame)];
    self.topAdView = [[YMAAdView alloc] initWithBlockID:<BlockID>
                                              adSize:adSize
                                            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.

    • [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];
  4. 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.

  5. 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;
    
    // Setting up a delegate that implements the YMAVideoDelegate protocol.
    videoController.delegate = self;
    
    // Implementing the YMAVideoDelegate protocol method.
    #pragma mark - YMAVideoDelegate
    - (void)videoControllerDidFinishPlayingVideo:(YMAVideoController *)videoController
    {
        NSLog(@"%@", @"Video complete");
    }