请输入
菜单

原生模版(NativeExpress)

原生模版广告接入

1. 原生模版广告介绍

原生模版广告是在列表页或轮播图上显示的广告类型。

2. 原生模版广告集成说明

  1. 原生对象可以重复请求,广告请求成功后,媒体自行存储 AMPSNativeExpressView 对象,如果未存储,重新 loadAd 后,上一个 AMPSNativeExpressView 对象会被移除;
  2. 原生重复拉取过多后。媒体可根据自身情况手动进行移除,防止内存占用过大。
  • 注:调用方法时,尽量在主线程调用,防止异步回到主线程增加请求耗时。

3. 原生模版广告API说明

3.1.1 AMPSNativeExpressManager 属性说明

属性 说明
adConfiguration 广告配置对象
delegate 广告代理声明
viewsArray 广告视图数组

3.1.2 AMPSNativeExpressManager 方法说明

方法 说明
initWithAdConfiguration: 创建初始化对象adConfiguration 广告配置
loadNativeExpressManager 广告请求
resetConfigurationAdSize: 重置广告配置尺寸
removeNativeExpressManager 销毁广告对象

3.1.3 AMPSNativeExpressManagerDelegate 代理说明

方法 说明
ampsNativeAdLoadSuccess: 原生广告加载成功
ampsNativeAdLoadFail: error: 原生广告加载失败

3.2.1 AMPSNativeExpressView 属性说明

属性 说明
viewController 广告点击弹出落地需要使用的控制器
delegate 广告视图代理声明

3.2.2 AMPSNativeExpressView 方法说明

方法 说明
renderAd 渲染广告视图
isReadyAd 是否可以用于显示
removeNativeAd 销毁原生广告视图
resetLayoutWithSize: 更新布局(仅ADN请求时支持)

3.2.3 AMPSNativeExpressViewDelegate 代理说明

方法 说明
ampsNativeAdRenderSuccess: 原生广告视图渲染成功
ampsNativeAdRenderFail: error: 原生广告视图渲染失败
ampsNativeAdExposured: 原生广告视图曝光
ampsNativeAdDidClick: 原生广告视图点击
ampsNativeAdDidClose: 原生广告视图关闭

4. 原生广告代码示例

广告加载与显示:

objc 复制代码
#import <AdScopeFoundation/AdScopeFoundation.h>
#import <AMPSAdSDK/AMPSAdSDK.h>

@interface AMPSADNNormalNativeExpressViewController () <AMPSNativeExpressManagerDelegate, AMPSNativeExpressViewDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) AMPSNativeExpressManager *nativeExpressManager;
@property (nonatomic, strong) AMPSNativeExpressView *adView;

@end

@implementation AMPSADNNormalNativeExpressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.scrollView];
    [self setScrollViewAutoLayout];
    
    AMPSAdConfiguration *cfg = [[AMPSAdConfiguration alloc]init];
    cfg.spaceId = kAdScopeDemoADNSDKNativeID;
    cfg.adSize = CGSizeMake(self.view.frame.size.width, 0);
    self.nativeExpressManager = [[AMPSNativeExpressManager alloc]initWithAdConfiguration:cfg];
    self.nativeExpressManager.delegate = self;
    [self.nativeExpressManager loadNativeExpressManager];
}

- (void)ampsNativeAdLoadSuccess:(AMPSNativeExpressManager *)nativeAd {
    CookieADNLog(@"AMPS-NativeExpress-LoadSuccess");
    for (int i = 0; i < nativeAd.viewsArray.count; i++) {
        AMPSNativeExpressView *adView = [nativeAd.viewsArray adScopeSafeObjectAtIndex:i];
        adView.delegate = self;
        adView.viewController = self;
        adView.backgroundColor = [UIColor orangeColor];
        [adView renderAd];
    }
}

- (void)ampsNativeAdRenderSuccess:(AMPSNativeExpressView *)nativeView {
    CookieADNLog(@"AMPS-NativeView-RenderSuccess");
    [self.scrollView addSubview:nativeView];
}

- (void)ampsNativeAdRenderFail:(AMPSNativeExpressView *)nativeView error:(NSError *_Nullable)error {
    CookieADNLog(@"AMPS-NativeExpress-LoadFail:%@", error);
}

- (void)ampsNativeAdExposured:(AMPSNativeExpressView *)nativeView {
    CookieADNLog(@"AMPS-NativeView-Exposured");
}

- (void)ampsNativeAdDidClick:(AMPSNativeExpressView *)nativeView {
    CookieADNLog(@"AMPS-NativeView-DidClick");
}

- (void)ampsNativeAdDidClose:(AMPSNativeExpressView *)nativeView {
    CookieADNLog(@"AMPS-NativeView-DidClose");
}

#pragma mark 页面视图
- (UIScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]init];
        _scrollView.backgroundColor = [UIColor whiteColor];
        _scrollView.scrollEnabled = YES;
        _scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height-kAdScopeDemoNavHeight-30);
        _scrollView.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _scrollView;
}

- (void)setScrollViewAutoLayout {
    NSDictionary *views = @{@"scrollView":self.scrollView};
    NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[scrollView]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:views];
    [self.view addConstraints:hConstraints];
    NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[scrollView]-0-|" options:NSLayoutFormatAlignAllCenterX metrics:nil views:views];
    [self.view addConstraints:vConstraints];
}

@end

5. 广告竞价逻辑

objc 复制代码
/**
 本次广告价格,单位分
 */
- (NSInteger)eCPM;

/**
 @pararm winInfo 竞胜信息,字典类型
 AMPS_WIN_PRICE :竞胜价格 (单位: 分),必填
 AMPS_WIN_ADNID :竞胜渠道ID,必填
 AMPS_HIGHRST_LOSS_PRICE :失败渠道中最高价格,必填
 AMPS_EXPECT_PRICE :期望价格,选填
 */
- (void)sendWinNotificationWithInfo:(NSDictionary *)winInfo;

/**
 @pararm lossInfo 竞败信息,字典类型
 AMPS_WIN_PRICE :竞胜价格 (单位: 分),必填
 AMPS_WIN_ADNID :竞胜渠道ID,必填
 AMPS_HIGHRST_LOSS_PRICE :失败渠道中最高价格,必填
 AMPS_LOSS_REASON :失败原因,必填
 AMPS_EXPECT_PRICE :期望价格,选填
 */
- (void)sendLossNotificationWithInfo:(NSDictionary *)lossInfo;

类型相关的枚举请参考:AMPSAdSDKDefines

6. 原生模版广告注意事项

  • 调用方法时,尽量在主线程调用,防止异步回到主线程增加请求耗时。
  • 原生模版广告高度可自适应,效果最优。
  • 原生模版广告 viewController 必须传。
  • 原生模版广告传入高度固定时,渠道返回的广告高度也是自适应的,须自己适配广告高度。
上一个
开屏(Splash)
下一个
原生自渲染(UnifiedNative)
最近修改: 2025-06-10