跳转到主要内容

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.

横幅和 MREC 广告位支持标准广告网络展示广告、支持 MRAID 3.0 的 CloudX 渲染 HTML 素材,以及通过服务端配置投放到横幅/MREC 广告位的原生素材。Meta、Vungle 和 Moloco 支持 native-in-banner 与 native-in-MREC,无需修改应用侧 API。

横幅广告 (320x50)

@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(@"横幅广告从 %@ 加载成功", ad.networkName);
}

- (void)didFailToLoadAd:(NSString *)adUnitId error:(CLXError *)error {
    NSLog(@"横幅广告加载失败: %@", error.localizedDescription);
}

- (void)didClickAd:(CLXAd *)ad {
    NSLog(@"横幅广告被点击");
}

// 可选:当横幅展开时调用(如 MRAID)
- (void)didExpandAd:(CLXAd *)ad {
    NSLog(@"横幅广告已展开");
}

// 可选:当横幅收起时调用
- (void)didCollapseAd:(CLXAd *)ad {
    NSLog(@"横幅广告已收起");
}

#pragma mark - CLXAdRevenueDelegate

- (void)didPayRevenueForAd:(CLXAd *)ad {
    NSLog(@"横幅广告收入: %@ 来自 %@", ad.revenue, ad.networkName);
}

@end
横幅广告默认自动刷新。手动控制刷新:
[self.bannerAd stopAutoRefresh];    // 停止自动刷新
[self.bannerAd load];               // 手动加载新广告
[self.bannerAd startAutoRefresh];   // 重新启用自动刷新
可选的展示位置和自定义数据用于追踪:
self.bannerAd.placement = @"home_screen";
self.bannerAd.customData = @"level:5,coins:100";

MREC 广告 (300x250)

@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.networkName);
}

- (void)didFailToLoadAd:(NSString *)adUnitId error:(CLXError *)error {
    NSLog(@"MREC 广告加载失败: %@", error.localizedDescription);
}

- (void)didClickAd:(CLXAd *)ad {
    NSLog(@"MREC 广告被点击");
}

// 可选:当 MREC 展开时调用(如 MRAID)
- (void)didExpandAd:(CLXAd *)ad {
    NSLog(@"MREC 广告已展开");
}

// 可选:当 MREC 收起时调用
- (void)didCollapseAd:(CLXAd *)ad {
    NSLog(@"MREC 广告已收起");
}

#pragma mark - CLXAdRevenueDelegate

- (void)didPayRevenueForAd:(CLXAd *)ad {
    NSLog(@"MREC 广告收入: %@ 来自 %@", ad.revenue, ad.networkName);
}

@end
MREC 广告也默认自动刷新。使用与横幅广告相同的刷新控制方法。