Ad slider

Native advertising is a type of ad whose layout can be defined at the app level. This feature allows you to change the visual style of ads and their placement, in the context of the app design specifics.

Ad rendering is performed with native platform tools, which enhances ad performance and quality.

Native ads enhance the overall ad experience, so you can show more ads while keeping users engaged. In the long run, this allows you to maximize your advertising revenue.

Prerequisite

  1. Follow the SDK integration steps described under Quick start.
  2. First, you need to initialize the advertising SDK.
  3. Make sure you're using the latest version of the Yandex Mobile Ads SDK, and if you're using mediation, the latest version of the unified build.

Loading the slider

  1. Create an instance of the SliderAdLoader class to load the ad slider.

  2. Create an AdRequest with the ad unit ID and NativeAdOptions for additional parameters.

  3. Call the loadAd(with:options:completion:) method to load an ad.

  4. When the ad loads, use the SliderAd object to display it.

  5. If an error occurs, resolve it.

let adLoader = SliderAdLoader()
let request = AdRequest(adUnitID: "<AdUnitID>")
let options = NativeAdOptions()

do {
    let sliderAd = try await adLoader.loadAd(with: request, options: options)
    // Show the ad
} catch {
    // Load error
}
let adLoader = SliderAdLoader()
let request = AdRequest(adUnitID: "<AdUnitID>")
let options = NativeAdOptions()

adLoader.loadAd(with: request, options: options) { [weak self] result in
    switch result {
    case .success(let sliderAd):
        // Render the ad
        break
    case .failure:
        break
    }
}

Rendering a native ad slider

Once the slider is loaded, you must render all its assets.

A successfully loaded slider contains one or more native ads having the same context. Ads in the slider must be displayed within the same shared container: otherwise, ad impressions won't count.

With this method, you can arrange the slider for your native ads by positioning ad components relative to each other. The ad may include both required and optional assets for display. For the full list, see Native ad assets.

Tip

For each ad in the slider, we recommend using a layout that includes a complete set of possible assets. In practical terms, such layouts result in higher conversion rates.

Call the bind(with:) method on the SliderAd object, passing the ad slider container.

Each ad in the slider is laid out using a standard native advertising layout method.

adLoader.loadAd(with: request, options: options) { [weak self] result in
    guard case .success(let sliderAd) = result else { return }

    sliderAd.delegate = self

    // Create a container for the slider; replace NativeAdView with your subclass
    let sliderAdView = NativeAdView()

    do {
        try sliderAd.bind(with: sliderAdView)
    } catch {
        // Check the error message and resolve the issue
        return
    }

    for subAd in sliderAd.ads {
        subAd.delegate = self

        // Create an ad view for each ad; replace NativeAdView with your subclass
        let subAdView = NativeAdView()

        do {
            try subAd.bind(with: subAdView)
        } catch {
            return
        }

        // Add the ad to the container and position it
        sliderAdView.addSubview(subAdView)
    }
}