请输入
菜单

开屏(Splash)

开屏广告接入

1. 开屏广告介绍

开屏广告是app启动时,显示的一种广告形式。

2. 开屏广告集成说明

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

3. 开屏广告API说明

3.1.1 AMPSSplashAd 属性说明

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

3.1.2 AMPSSplashAd 方法说明

方法 说明
initWithAdConfiguration: 创建初始化对象adConfiguration 广告配置
loadSplashAd 广告请求
showSplashViewInWindow: 显示广告
showSplashViewInWindow:bottomView: 显示广告并设置LogoView
removeSplashAd 销毁开屏广告对象

3.1.3 AMPSSplashAdDelegate 代理说明

方法 说明
ampsSplashAdLoadSuccess: 开屏广告加载成功
ampsSplashAdLoadFail: error: 开屏广告加载失败
ampsSplashAdRenderSuccess: 开屏广告渲染成功
ampsSplashAdRenderFail: error: 开屏广告渲染失败
ampsSplashAdDidShow: 开屏广告显示
ampsSplashAdShowFail: error: 开屏广告显示失败
ampsSplashAdExposured: 开屏广告曝光
ampsSplashAdDidClick: 开屏广告点击
ampsSplashAdDidClose: 开屏广告关闭

4. 开屏广告代码示例

广告加载与显示:

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

@interface AppDelegate ()<AMPSSplashAdDelegate>

@property (nonatomic, strong) AMPSSplashAd *splash;

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[AMPSAdSDKManager sharedInstance]startAsyncWithAppId:kAdScopeDemoADNInitSDKAPPID configuration:nil results:^(AMPSAdSDKInitStatus statusResult) {
        [self requestSplashAd];
    }];
    return YES;
}

- (void)requestSplashAd {
    [self.view endEditing:YES];
    AMPSAdConfiguration *cfg = [[AMPSAdConfiguration alloc]init];
    cfg.spaceId = @"广告位ID";
    self.splashAd = [[AMPSSplashAd alloc]initWithAdConfiguration:cfg];
    self.splashAd.delegate = self;
    [self.splashAd loadSplashAd];
}

- (void)ampsSplashAdLoadSuccess:(AMPSSplashAd *)splashAd {
    CookieADNLog(@"ampsSplashAdLoadSuccess");
}
- (void)ampsSplashAdLoadFail:(AMPSSplashAd *)splashAd error:(NSError *_Nullable)error {
    CookieADNLog(@"ampsSplashAdLoadFail:%@", error);
}
- (void)ampsSplashAdRenderFail:(AMPSSplashAd *)splashAd error:(NSError * _Nullable)error {
    CookieADNLog(@"ampsSplashAdRenderFail:%@", error);
}
- (void)ampsSplashAdRenderSuccess:(AMPSSplashAd *)splashAd {
    CookieADNLog(@"ampsSplashAdRenderSuccess");
    UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kAdScopeDemoScreenWidth, 160)];
    bottomView.backgroundColor = [UIColor adScopeColorWithHexString:@"#6495ED"];
    [self.splash showSplashViewInWindow:[UIApplication sharedApplication].keyWindow bottomView:bottomView];
}
- (void)ampsSplashAdDidShow:(AMPSSplashAd *)splashAd {
    CookieADNLog(@"ampsSplashAdDidShow");
}
- (void)ampsSplashAdExposured:(AMPSSplashAd *)splashAd {
    CookieADNLog(@"ampsSplashAdExposured");
}
- (void)ampsSplashAdDidClick:(AMPSSplashAd *)splashAd {
    CookieADNLog(@"ampsSplashAdDidClick");
}
- (void)ampsSplashAdDidClose:(AMPSSplashAd *)splashAd {
    CookieADNLog(@"ampsSplashAdDidClose");
}
- (void)ampsSplashAdShowFail:(AMPSSplashAd *)splashAd error:(NSError * _Nullable)error {
    CookieADNLog(@"ampsSplashAdShowFail:%@", error);
}

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. 开屏广告注意事项

  • 调用方法时,尽量在主线程调用,防止异步回到主线程增加请求耗时。
  • 广告需要在ampsSplashAdRenderSuccess后调用显示。
  • 确保展示时传入的window是keyWindow,否则可能会出现广告展示无效,keyWindow需要确保存在rootViewController,防止广告落地页无法正常弹出。
上一个
SDK初始化及API说明
下一个
原生模版(NativeExpress)
最近修改: 2025-01-10