Enabling VAST ads

VAST ads are a set of YMAVASTAd objects that contain video ads. Video ads conform to the VAST (Video Ad Serving Template) standard.

The Yandex Mobile Ads SDK supports VAST 2.0 and 3.0.

To enable VAST ads:
  1. Load the Vmap object that contains a set of YMAAdBreak objects and the Extensions list.
  2. For the received YMAAdBreak objects, load video ads (a set of YMAVideoAd objects).

Loading VMAP

  1. Create an object of the YMAVMAPLoader class.

    YMAVMAPLoader *VMAPLoader = [[YMAVMAPLoader alloc] init];
  2. Implement the YMAVMAPLoaderDelegate protocol and set a delegate for the loader.
    adLoader.delegate = self;
  3. Call the – loadVMAPWithRequestConfiguration: method for the loader and pass an object of the YMAMutableVMAPRequestConfiguration class as a parameter. You can use it to set parameters for targeting ads.

    Example of VMAP loading
    @interface VMAPController () <YMAVMAPLoaderDelegate>
    
    @property (nonatomic, strong) YMAVMAPLoader *VMAPLoader;
    
    ...
    
    @end
    
    @implementation VMAPController
    
    ...
    
    - (void)loadVMAP
    {
        // Creating a loader.
        self.VMAPLoader = [[YMAVMAPLoader alloc] init];
        
        // Setting up a delegate.
        self.VMAPLoader.delegate = self;
    
        // Creating a request configuration.
        YMAMutableVMAPRequestConfiguration *VMAPRequestConfiguration =
            [[YMAMutableVMAPRequestConfiguration alloc] initWithPageID:pageID];
        VMAPRequestConfiguration.categoryID = categoryID;
        
        // Loading VMAP.
        [self.VMAPLoader loadVMAPWithRequestConfiguration:VMAPRequestConfiguration];
    }
    
    ...
    
    - (void)loader:(YMAVMAPLoader *)loader didLoadVMAP:(YMAVMAP *)VMAP
    {
        // VMAP loaded successfully.
        ...
    }
    
    - (void)loader:(YMAVMAPLoader *)loader didFailLoadingVMAPWithError:(NSError *)error
    {
        // VMAP loading failed.
        ...
    }
    
    ...
    
    @end
    
  4. The received response to the request for VMAP contains an array of YMAVMAPAdBreak class objects required for loading video ads and a variety of settings that can be useful for the player.

Loading video ads

  1. Create an object of the YMAVASTRequestConfiguration class using an object of the YMAVMAPAdBreak class received in response to the request for VMAP. You can also set parameters for targeting.

    YMAMutableVASTRequestConfiguration *configuration =
         [[YMAMutableVASTRequestConfiguration alloc] initWithAdBreak:self.adBreak];
    // Optional parameters for targeting.
    configuration.parameters = @{ ... };
  2. Create an object of the YMAVideoAdLoader class.
  3. Implement the YMAVideoAdLoaderDelegate protocol and set a delegate for the loader.
    videoaAdLoader.delegate = self;
  4. Call the – loadVMAPWithRequestConfiguration: method.

    Example of loading video ads
    @interface VMAPController () <YMAVMAPLoaderDelegate>
    
    @property (nonatomic, strong) YMAVideoAdLoader *videoAdLoader;
    @property (nonatomic, strong) YMAVMAP *VMAP;
    
    ...
    
    @end
    
    @implementation VMAPController
    
    ...
    
    - (void)loadVMAP
    {
        // Creating a loader.
        self.videoAdLoader = [[YMAVideoAdLoader alloc] init];
        
        // Setting up a delegate.
        self.videoAdLoader.delegate = self;
    
        // Creating a request configuration using the adBreak from the VMAP response.
        YMAMutableVASTRequestConfiguration *configuration =
             [[YMAMutableVASTRequestConfiguration alloc] initWithAdBreak:self.VMAP.adBreaks[0]];
        
        // Additional parameters for targeting.
        configuration.parameters = @{ @"puid1": @"example1", @"puid2": @"example2" };
        
        // Loading.
        [self.videoAdLoader loadVASTWithRequestConfiguration:VASTRequestConfiguration];
    }
    
    ...
    
    - (void)loaderDidLoadVideoAds:(NSArray<YMAVASTAd *> *)ads
    {
        // Ads loaded successfully.
        ...
    }
    
    - (void)loaderDidFailLoadingVideoAdsWithError:(NSError *)error
    {
        // Loading failed.
        ...
    }
    
    ...
    
    @end
  5. A response is considered successful if it contains a list of YMAVASTAd objects. Each object contains VAST ads.