请输入
菜单

插屏(Interstitial)

插屏广告接入

1. 插屏广告介绍

插屏广告是app等待时,给用户显示的广告类型。

2. 插屏广告集成说明

  1. 插屏对象可以重复请求,广告请求成功后,未调用显示前不要重复拉取;
  2. 插屏关闭后可再次调用 loadInterstitialAd 后会重新拉取广告。
  3. 不在使用广告对象时,可手动调用 removeInterstitialAd 防止异常时内存无法释放。
  • 注:调用方法时,尽量在主线程调用,防止异步回到主线程增加请求耗时。

3. 插屏广告API说明

3.1.1 AMPSInterstitialAd 属性说明

属性 说明
adConfiguration 广告配置对象
delegate 广告代理声明

3.1.2 AMPSInterstitialAd 方法说明

方法 说明
initWithAdConfiguration: 创建初始化对象adConfiguration 广告配置
loadInterstitialAd 广告请求
showInterstitialAdWithRootViewController: 显示插屏广告
removeInterstitialAd 销毁插屏广告对象

3.1.3 AMPSInterstitialAdDelegate 代理说明

方法 说明
ampsInterstitialAdLoadSuccess: 插屏广告加载成功
ampsInterstitialAdLoadFail: error: 插屏广告加载失败
ampsInterstitialAdRenderSuccess: 插屏广告渲染成功
ampsInterstitialAdRenderFail: error: 插屏广告渲染失败
ampsInterstitialAdDidShow: 插屏广告显示
ampsInterstitialAdShowFail: error: 插屏广告显示失败
ampsInterstitialAdDidClick: 插屏广告点击
ampsInterstitialAdDidClose: 插屏广告关闭

4. 插屏广告代码示例

广告加载与显示:

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

@interface AMPSADNInterstitialViewController () <AMPSInterstitialAdDelegate>

@property (nonatomic, strong) AMPSInterstitialAd *interstitialAd;

@property (nonatomic, strong) UILabel *resultsLabel;

@end

@implementation AMPSADNInterstitialViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *requestBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [requestBtn setTitleColor:[UIColor adScopeColorWithHexString:@"#000000"] forState:UIControlStateNormal];
    [requestBtn setTitle:@"请求广告" forState:UIControlStateNormal];
    requestBtn.frame = CGRectMake(15, kAdScopeDemoNavHeight+15, self.view.frame.size.width-30, 40);
    requestBtn.layer.masksToBounds = YES;
    requestBtn.layer.borderWidth = 1;
    requestBtn.layer.borderColor = [UIColor adScopeColorWithHexString:@"999999"].CGColor;
    requestBtn.layer.cornerRadius = 3;
    [requestBtn addTarget:self action:@selector(requestBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:requestBtn];
    
    UIButton *showBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [showBtn setTitleColor:[UIColor adScopeColorWithHexString:@"#000000"] forState:UIControlStateNormal];
    [showBtn setTitle:@"显示广告" forState:UIControlStateNormal];
    showBtn.frame = CGRectMake(requestBtn.adScopeFrameLeft, requestBtn.adScopeFrameBottom+15, requestBtn.adScopeFrameWidth, 40);
    showBtn.layer.masksToBounds = YES;
    showBtn.layer.borderWidth = 1;
    showBtn.layer.borderColor = [UIColor adScopeColorWithHexString:@"999999"].CGColor;
    showBtn.layer.cornerRadius = 3;
    [showBtn addTarget:self action:@selector(showBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:showBtn];
    
    self.resultsLabel = [[UILabel alloc]initWithFrame:CGRectMake(showBtn.adScopeFrameLeft, showBtn.adScopeFrameBottom+15, showBtn.adScopeFrameWidth, 30)];
    self.resultsLabel.textColor = [UIColor redColor];
    self.resultsLabel.textAlignment = NSTextAlignmentCenter;
    self.resultsLabel.text = @"广告请求日志";
    [self.view addSubview:self.resultsLabel];
}

- (void)requestBtnClick {
    AMPSAdConfiguration *cfg = [[AMPSAdConfiguration alloc]init];
    cfg.spaceId = kAdScopeDemoADNSDKInterstitialID;
    self.interstitialAd = [[AMPSInterstitialAd alloc]initWithAdConfiguration:cfg];
    self.interstitialAd.delegate = self;
    [self.interstitialAd loadInterstitialAd];
    self.resultsLabel.text = @"请求中。。。";
}

- (void)showBtnClick {
    [self.view endEditing:YES];
    [self.interstitialAd showInterstitialAdWithRootViewController:self];
}

- (void)ampsInterstitialAdLoadSuccess:(AMPSInterstitialAd *)interstitialAd {
    CookieADNLog(@"ampsInterstitialAdLoadSuccess");
}

- (void)ampsInterstitialAdLoadFail:(AMPSInterstitialAd *)interstitialAd error:(NSError *_Nullable)error {
    self.resultsLabel.text = [NSString stringWithFormat:@"请求失败:%ld", error.code];
    CookieADNLog(@"ampsInterstitialAdLoadFail:%@", error);
    self.interstitialAd = nil;
}

- (void)ampsInterstitialAdRenderSuccess:(AMPSInterstitialAd *)interstitialAd {
    self.resultsLabel.text = @"广告请求成功";
    CookieADNLog(@"ampsInterstitialAdRenderSuccess");
}

- (void)ampsInterstitialAdRenderFail:(AMPSInterstitialAd *)interstitialAd error:(NSError *_Nullable)error {
    self.resultsLabel.text = [NSString stringWithFormat:@"渲染失败:%ld", error.code];
    CookieADNLog(@"ampsInterstitialAdRenderFail:%@", error);
    self.interstitialAd = nil;
}

- (void)ampsInterstitialAdShowFail:(AMPSInterstitialAd *)interstitialAd error:(NSError *_Nullable)error {
    self.resultsLabel.text = [NSString stringWithFormat:@"显示失败:%ld", error.code];
    CookieADNLog(@"ampsInterstitialAdShowFail:%@", error);
    self.interstitialAd = nil;
}

- (void)ampsInterstitialAdDidShow:(AMPSInterstitialAd *)interstitialAd {
    CookieADNLog(@"ampsInterstitialAdDidShow");
}

- (void)ampsInterstitialAdDidClick:(AMPSInterstitialAd *)interstitialAd {
    CookieADNLog(@"ampsInterstitialAdDidClick");
}

- (void)ampsInterstitialAdDidClose:(AMPSInterstitialAd *)interstitialAd {
    self.resultsLabel.text = @"广告已关闭";
    CookieADNLog(@"ampsInterstitialAdDidClose");
}

@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

上一个
原生自渲染(UnifiedNative)
下一个
错误码说明
最近修改: 2025-01-10