Android iOS Unity JS API 常见问题

开屏广告

简介

基本信息

开屏广告以App启动作为曝光时机,提供5s的可感知广告展示。用户可以点击广告跳转到目标页面;或者点击右上角的“跳过”按钮,跳转到app内容首页
权限等级:开放

适用场景:开屏广告会在您的应用开启时加载,拥有固定展示时间(一般为5秒),展示完毕后自动关闭并进入您的应用主界面。
分类:开屏广告分为半屏和全屏,其中半屏开屏广告支持开发者自定义设置开屏底部的界面,用以展示应用Logo等。具体种类可以在开发者平台进行选择:

半屏 全屏

主要API

生命周期事件回调

您可以实现全部或部分GDTSplashAdDelegate,以跟踪点击成功或者插屏广告请求失败等广告生命周期事件。

@protocol GDTSplashAdDelegate <NSObject>
@optional
- (void)splashAdSuccessPresentScreen;
- (void)splashAdFailToPresent:error;
- (void)splashAdApplicationWillEnterBackground;
- (void)splashAdExposured;
- (void)splashAdClicked;
- (void)splashAdWillClosed;
- (void)splashAdClosed;
- (void)splashAdWillPresentFullScreenModal;
- (void)splashAdDidPresentFullScreenModal;
- (void)splashAdWillDismissFullScreenModal;
- (void)splashAdDidDismissFullScreenModal;
- (void)splashAdLifeTime;
@end

在实现上述事件回调之前,请务必先设置delegate:

Objective-C
self.splashAd.delegate = self;
Swift
splashAd.delegate = self

回调函数列表

回调函数名 回调函数含义
splashAdSuccessPresentScreen 开屏广告成功展示
splashAdFailToPresent 开屏广告展示失败
splashAdApplicationWillEnterBackground 当点击下载应用时会调用系统程序打开,应用切换到后台
splashAdExposured 开屏广告曝光回调
splashAdClicked 开屏广告点击回调
splashAdWillClosed 开屏广告将要关闭回调
splashAdClosed 开屏广告关闭回调
splashAdWillPresentFullScreenModal 开屏广告点击以后即将弹出全屏广告页
splashAdDidPresentFullScreenModal 开屏广告点击以后弹出全屏广告页
splashAdWillDismissFullScreenModal 点击以后全屏广告页将要关闭
splashAdDidDismissFullScreenModal 点击以后全屏广告页已经关闭
splashAdLifeTime 开屏广告剩余时间回调

多阶底价能力

接入多阶底价能力分2步:

step1:

找优量汇运营同学开通广告位的多阶底价权限并提供底价配置信息;

step2:

当广告拉取成功后,通过GDTRewardVideoAd类的eCPMLevel属性查看当前激励视频广告对应的底价层级。

/**
 返回广告的eCPM等级

 @return 成功返回一个包含数字的string,比如@"2"表示底价等级为2,@""或nil表示无权限或后台异常
 */
@property (nonatomic, readonly) NSString *eCPMLevel;

接入代码示例

加载并显示开屏广告

1.在AppDelegate头文件中导入头文件并声明实例

Objective-C
 #import "GDTSplashAd.h"
 @interface GDTAppDelegate : UIResponder <UIApplicationDelegate,GDTSplashAdDelegate>
 @property (strong, nonatomic) GDTSplashAd *splash;
 @property (retain, nonatomic) UIView *bottomView;
 @end
Swift
class SplashViewController: UIViewController,GDTSplashAdDelegate {
    private var splashAd: GDTSplashAd!
    private var bottomView: UIView!
    ...
  }

2.在AppDelegate的实现文件中初始化并加载广告数据,开屏广告目前支持全屏开屏和半屏开屏广告两种形式,其中半屏开屏广告支持开发者自定义设置开屏底部的界面,用以展示应用Logo等。

 /**
 *  发起拉取广告请求,只拉取不展示
 *  详解:广告素材及广告图片拉取成功后会回调splashAdDidLoad方法,当拉取失败时会回调splashAdFailToPresent方法
 */
- (void)loadAd;

/**
 *  展示广告,调用此方法前需调用isAdValid方法判断广告素材是否有效
 *  详解:广告展示成功时会回调splashAdSuccessPresentScreen方法,展示失败时会回调splashAdFailToPresent方法
 */
- (void)showAdInWindow:(UIWindow *)window withBottomView:(UIView *)bottomView skipView:(UIView *)skipView;

/**
 * 返回广告是否可展示
 * 对于并行请求,在调用showAdInWindow前时需判断下
 * @return 当广告已经加载完成且未曝光时,为YES,否则为NO
 */
- (BOOL)isAdValid;
Objective-C
  // splash LoadAd 逻辑
  GDTSplashAd *splash = [[GDTSplashAd alloc] initWithPlacementId:YOUR_PLACEMENT_ID];
  splash.delegate = self; //设置代理
  //根据iPhone设备不同设置不同背景图
  if ([[UIScreen mainScreen] bounds].size.height >= 568.0f) {
   splash.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"LaunchImage-568h"]];
  } else {
   splash.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"LaunchImage"]];
  }
  splash.fetchDelay = 3; //开发者可以设置开屏拉取时间,超时则放弃展示
  [splashAd loadAd];

  ......

  // splash show逻辑
  //设置开屏底部自定义LogoView,展示半屏开屏广告
  _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 100)];
  UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SplashBottomLogo"]];
  [_bottomView addSubview:logo];
  logo.center = _bottomView.center;
  _bottomView.backgroundColor = [UIColor whiteColor];
  UIWindow *window = [[UIApplication sharedApplication] keyWindow];
  [splashAd showAdInWindow:window withBottomView:_bottomView skipView:nil];
Swift
  // splash LoadAd 逻辑
  splashAd = GDTSplashAd.init(placementId: YOUR_PLACEMENT_ID)
  splashAd.delegate = self
  splashAd.fetchDelay = 3
  var splashImage = UIImage.init(named: "SplashNormal")
  if Util.isIphoneX() {
      splashImage = UIImage.init(named: "SplashX")
  } else if Util.isSmallIphone() {
      splashImage = UIImage.init(named: "SplashSmall")
  }
  splashAd.backgroundImage = splashImage
  self.splashAd.load()

  // splash show逻辑
  bottomView = UIView.init(frame: CGRect(origin: CGPoint.zero, size: CGSize(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.height * 0.25)))
  bottomView.backgroundColor = .white
  let logo = UIImageView.init(image: UIImage.init(named: "SplashLogo"))
  logo.frame = CGRect(origin: CGPoint.zero, size: CGSize(width: 311, height: 47))
  logo.center = bottomView.center
  bottomView.addSubview(logo)
  let window = UIApplication.shared.keyWindow
  splashAd.show(in: window, withBottomView:  bottomView, skip: nil)

3.将YOUR_PLACEMENT_ID替换成你自己的PLACEMENTID。

说明

目前开屏广告只针对iPhone设备在垂直方向上展示。
广告发起请求并展示在Window中,同时在屏幕底部设置应用自身的Logo页面或是自定义View,Logo页面或是自定义View所占的空间不能过大,高度不能超过屏幕高度的 25%。

设置自定义跳过按钮

您可以设置自定义跳过按钮,可以通过设置skipView的frame来修改自定义按钮的位置及大小。

Objective-C
UIView *customSkipView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)]; // 设置跳过按钮的frame信息
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
[self.splashAd showAdInWindow:window withBottomView:self.bottomView skipView:customSkipView];
Swift
let customView = UIView.init(frame: CGRect(x: 0,y: 0,width: 100,height: 50)) // 设置跳过按钮的frame信息
let window = UIApplication.shared.keyWindow
self.splashAd.show(in: window, withBottomView:  bottomView, skip: customView)

开屏广告拉取超时时间

您可以设置拉取广告的超时时间,默认为3秒。通常情况,开发者调用loadAd后开始计时,如果在该时间内广告拉取成功,则返回成功回调;否则返回超时回调。

Objective-C
self.splashAd.fetchDelay = 5;
Swift
splashAd.fetchDelay = 5

在不展示开屏广告时执行调试

在您的ViewController里实现如下回调,处理开屏广告加载失败的问题:

Objective-C
- (void)splashAdFailToPresent:(GDTSplashAd *)splashAd 
withError:(NSError *)error
{
    NSLog(@"%s%@",__FUNCTION__,error);
}
Swift
func splashAdFail(toPresent splashAd: GDTSplashAd!, withError error: Error!) {
    print(#function,error)
}

说明:开屏广告只支持竖屏使用。

预加载开屏合约广告

联盟开屏广告支持预加载合约开屏广告,调用方法如下:

[GDTSplashAd preloadSplashOrderWithPlacementId:YOUR_PLACEMENT_ID];

说明:将YOUR_PLACEMENT_ID替换成你自己的PLACEMENTID。

Copyright © 1998 - 2020 Tencent Inc. All Rights Reserved.
腾讯公司 版权所有 | 加入优量汇