> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloudx.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Banner & MREC Ads

> Integrate CloudX banner and MREC ads in iOS apps

Banner and MREC placements support standard network display ads, CloudX-rendered HTML creatives with MRAID 3.0 support, and native creatives served into banner/MREC slots when configured server-side. Native-in-banner and native-in-MREC demand is supported for Meta, Vungle, and Moloco without app-side API changes.

## Banner Ads (320x50)

<CodeGroup>
  ```objc Objective-C theme={null}
  @interface YourViewController () <CLXBannerDelegate, CLXAdRevenueDelegate>
  @property (nonatomic, strong) CLXBannerAdView *bannerAd;
  @end

  @implementation YourViewController

  - (void)createBannerAd {
      self.bannerAd = [[CloudXCore shared] createBannerWithAdUnitId:@"your-banner-ad-unit-id"];
      self.bannerAd.delegate = self;
      self.bannerAd.revenueDelegate = self;

      if (self.bannerAd) {
          self.bannerAd.translatesAutoresizingMaskIntoConstraints = NO;
          [self.view addSubview:self.bannerAd];

          [NSLayoutConstraint activateConstraints:@[
              [self.bannerAd.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor],
              [self.bannerAd.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
              [self.bannerAd.widthAnchor constraintEqualToConstant:320],
              [self.bannerAd.heightAnchor constraintEqualToConstant:50]
          ]];

          [self.bannerAd load];
      }
  }

  - (void)dealloc {
      [self.bannerAd destroy];
  }

  #pragma mark - CLXBannerDelegate

  - (void)didLoadAd:(CLXAd *)ad {
      NSLog(@"Banner ad loaded from %@", ad.networkName);
  }

  - (void)didFailToLoadAd:(NSString *)adUnitId error:(CLXError *)error {
      NSLog(@"Banner ad failed to load: %@", error.localizedDescription);
  }

  - (void)didClickAd:(CLXAd *)ad {
      NSLog(@"Banner ad clicked");
  }

  // Optional: Called when banner expands (e.g., MRAID)
  - (void)didExpandAd:(CLXAd *)ad {
      NSLog(@"Banner ad expanded");
  }

  // Optional: Called when banner collapses
  - (void)didCollapseAd:(CLXAd *)ad {
      NSLog(@"Banner ad collapsed");
  }

  #pragma mark - CLXAdRevenueDelegate

  - (void)didPayRevenueForAd:(CLXAd *)ad {
      NSLog(@"Banner revenue: %@ from %@", ad.revenue, ad.networkName);
  }

  @end
  ```

  ```swift Swift theme={null}
  class YourViewController: UIViewController, CLXBannerDelegate, CLXAdRevenueDelegate {
      private var bannerAd: CLXBannerAdView?

      func createBannerAd() {
          bannerAd = CloudXCore.shared.createBanner(adUnitId: "your-banner-ad-unit-id")
          bannerAd?.delegate = self
          bannerAd?.revenueDelegate = self

          if let bannerAd = bannerAd {
              bannerAd.translatesAutoresizingMaskIntoConstraints = false
              view.addSubview(bannerAd)

              NSLayoutConstraint.activate([
                  bannerAd.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
                  bannerAd.centerXAnchor.constraint(equalTo: view.centerXAnchor),
                  bannerAd.widthAnchor.constraint(equalToConstant: 320),
                  bannerAd.heightAnchor.constraint(equalToConstant: 50)
              ])

              bannerAd.load()
          }
      }

      deinit {
          bannerAd?.destroy()
      }

      // MARK: - CLXBannerDelegate

      func didLoad(_ ad: CLXAd) {
          print("Banner ad loaded from \(ad.networkName ?? "unknown")")
      }

      func didFailToLoadAd(_ adUnitId: String, error: CLXError) {
          print("Banner ad failed to load: \(error.localizedDescription)")
      }

      func didClick(_ ad: CLXAd) {
          print("Banner ad clicked")
      }

      // Optional: Called when banner expands (e.g., MRAID)
      func didExpand(_ ad: CLXAd) {
          print("Banner ad expanded")
      }

      // Optional: Called when banner collapses
      func didCollapse(_ ad: CLXAd) {
          print("Banner ad collapsed")
      }

      // MARK: - CLXAdRevenueDelegate

      func didPayRevenue(for ad: CLXAd) {
          print("Banner revenue: \(ad.revenue ?? 0) from \(ad.networkName ?? "unknown")")
      }
  }
  ```
</CodeGroup>

Banner ads auto-refresh by default. To control refresh manually:

<CodeGroup>
  ```objc Objective-C theme={null}
  [self.bannerAd stopAutoRefresh];    // Stop auto-refresh
  [self.bannerAd load];               // Manually load a new ad
  [self.bannerAd startAutoRefresh];   // Re-enable auto-refresh
  ```

  ```swift Swift theme={null}
  bannerAd?.stopAutoRefresh()    // Stop auto-refresh
  bannerAd?.load()               // Manually load a new ad
  bannerAd?.startAutoRefresh()   // Re-enable auto-refresh
  ```
</CodeGroup>

Optional placement and custom data for tracking:

<CodeGroup>
  ```objc Objective-C theme={null}
  self.bannerAd.placement = @"home_screen";
  self.bannerAd.customData = @"level:5,coins:100";
  ```

  ```swift Swift theme={null}
  bannerAd?.placement = "home_screen"
  bannerAd?.customData = "level:5,coins:100"
  ```
</CodeGroup>

## MREC Ads (300x250)

<CodeGroup>
  ```objc Objective-C theme={null}
  @interface YourViewController () <CLXBannerDelegate, CLXAdRevenueDelegate>
  @property (nonatomic, strong) CLXBannerAdView *mrecAd;
  @end

  @implementation YourViewController

  - (void)createMRECAd {
      self.mrecAd = [[CloudXCore shared] createMRECWithAdUnitId:@"your-mrec-ad-unit-id"];
      self.mrecAd.delegate = self;
      self.mrecAd.revenueDelegate = self;

      if (self.mrecAd) {
          self.mrecAd.translatesAutoresizingMaskIntoConstraints = NO;
          [self.view addSubview:self.mrecAd];

          [NSLayoutConstraint activateConstraints:@[
              [self.mrecAd.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
              [self.mrecAd.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor constant:-20],
              [self.mrecAd.widthAnchor constraintEqualToConstant:300],
              [self.mrecAd.heightAnchor constraintEqualToConstant:250]
          ]];

          [self.mrecAd load];
      }
  }

  - (void)dealloc {
      [self.mrecAd destroy];
  }

  #pragma mark - CLXBannerDelegate

  - (void)didLoadAd:(CLXAd *)ad {
      NSLog(@"MREC ad loaded from %@", ad.networkName);
  }

  - (void)didFailToLoadAd:(NSString *)adUnitId error:(CLXError *)error {
      NSLog(@"MREC ad failed to load: %@", error.localizedDescription);
  }

  - (void)didClickAd:(CLXAd *)ad {
      NSLog(@"MREC ad clicked");
  }

  // Optional: Called when MREC expands (e.g., MRAID)
  - (void)didExpandAd:(CLXAd *)ad {
      NSLog(@"MREC ad expanded");
  }

  // Optional: Called when MREC collapses
  - (void)didCollapseAd:(CLXAd *)ad {
      NSLog(@"MREC ad collapsed");
  }

  #pragma mark - CLXAdRevenueDelegate

  - (void)didPayRevenueForAd:(CLXAd *)ad {
      NSLog(@"MREC revenue: %@ from %@", ad.revenue, ad.networkName);
  }

  @end
  ```

  ```swift Swift theme={null}
  class YourViewController: UIViewController, CLXBannerDelegate, CLXAdRevenueDelegate {
      private var mrecAd: CLXBannerAdView?

      func createMRECAd() {
          mrecAd = CloudXCore.shared.createMREC(adUnitId: "your-mrec-ad-unit-id")
          mrecAd?.delegate = self
          mrecAd?.revenueDelegate = self

          if let mrecAd = mrecAd {
              mrecAd.translatesAutoresizingMaskIntoConstraints = false
              view.addSubview(mrecAd)

              NSLayoutConstraint.activate([
                  mrecAd.centerXAnchor.constraint(equalTo: view.centerXAnchor),
                  mrecAd.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -20),
                  mrecAd.widthAnchor.constraint(equalToConstant: 300),
                  mrecAd.heightAnchor.constraint(equalToConstant: 250)
              ])

              mrecAd.load()
          }
      }

      deinit {
          mrecAd?.destroy()
      }

      // MARK: - CLXBannerDelegate

      func didLoad(_ ad: CLXAd) {
          print("MREC ad loaded from \(ad.networkName ?? "unknown")")
      }

      func didFailToLoadAd(_ adUnitId: String, error: CLXError) {
          print("MREC ad failed to load: \(error.localizedDescription)")
      }

      func didClick(_ ad: CLXAd) {
          print("MREC ad clicked")
      }

      // Optional: Called when MREC expands (e.g., MRAID)
      func didExpand(_ ad: CLXAd) {
          print("MREC ad expanded")
      }

      // Optional: Called when MREC collapses
      func didCollapse(_ ad: CLXAd) {
          print("MREC ad collapsed")
      }

      // MARK: - CLXAdRevenueDelegate

      func didPayRevenue(for ad: CLXAd) {
          print("MREC revenue: \(ad.revenue ?? 0) from \(ad.networkName ?? "unknown")")
      }
  }
  ```
</CodeGroup>

MREC ads also auto-refresh by default. Use the same refresh control methods as Banner ads.
