MediaView integration guide


Integration is described using the example of an ImageAd.

  1. Enable the Mobile Ads SDK.

    Add dependencies to the Podfile project:

    pod 'YandexMobileAds', '2.17.0'

    If the Podfile has the line use_frameworks!, we recommend using the dynamic framework.

  2. Load the native ad.

    1. Create an object of the YMANativeAdLoader class with the configuration YMANativeAdLoaderConfiguration.
    2. Set a delegate for the created YMANativeAdLoader object.
    3. Call the – loadAdWithRequest: method.
  3. Display the native ad.

    Restriction. Requirements for mediaView size when displaying video ads

    Minimum size of an instance of the YMANativeMediaView class, which supports video playback: 300x160 or 160x300.

    To support video playback in native ads, we recommend setting the width for mediaView to at least 300. To calculate the appropriate mediaView height value, use the aspectRatio property value. When displaying ads using templates, the correct height for mediaView will be calculated automatically based on the width to height ratio.

    1. For an easy way to display an ad, use the templates.
      1. Create an object of the YMANativeBannerView class.
      2. Set the loaded ad object for it.
      - (void)viewDidLoad
          [super viewDidLoad];
        YMANativeAdLoaderConfiguration *configuration =
                [[YMANativeAdLoaderConfiguration alloc] initWithBlockID:@"your_block"
            self.adLoader = [[YMANativeAdLoader alloc] initWithConfiguration:configuration];
            self.adLoader.delegate = self;
            [self.adLoader loadAdWithRequest:nil];
      - (void)nativeAdLoader:(YMANativeAdLoader *)loader didLoadImageAd:(id<YMANativeImageAd>)ad
          YMANativeBannerView *bannerView = [[YMANativeBannerView alloc] init];
 = ad;
          [self.view addSubview:bannerView];
      - (void)nativeAdLoader:(YMANativeAdLoader *)loader didFailLoadingWithError:(NSError *)error
          // handle error

      For more information about native advertising, see Enabling native ads.

    2. You can also use the manual method to display native ads. This allows you to adapt native ads to your main content as closely as possible.

      1. Define the subview value for the YMANativeImageAdView object.

                UIButton *feedbackButton = [self button];
                YMANativeMediaView *mediaView = [self mediaAssetView];
                self.feedbackButton = feedbackButton;
                self.mediaView = mediaView;
                [self addSubview:self.mediaView];
                [self addSubview:self.feedbackButton];
      2. Call the – bindImageAdToView:delegate:error: method.

        - (void)nativeAdLoader:(YMANativeAdLoader *)loader didLoadImageAd:(id<YMANativeImageAd>)ad
            NSError * __autoreleasing error = nil;
            [ad bindImageAdToView:self.imageAdView delegate:self error:&error];
            [self configureViewForAd:ad];
            [self.view addSubview:self.imageAdView];
        - (void)configureViewForAd:(id<YMANativeGenericAd>)ad
            YMANativeAdAssets *assets = [ad adAssets];
            if ( {
                self.imageAdView.feedbackButton.hidden = NO;
            else {
                self.imageAdView.feedbackButton.hidden = YES;
            YMANativeAdMedia *media =;
            if (media != nil) {
                //you can use the aspect ratio if you need it to determine the size of media view.
                NSLog(@"Media aspect ratio: %.2f", media.aspectRatio);

        For more information about native advertising, see Layout without a template.