广点通开发文档里给的示例代码:
GDTSplashAd *splash = [[GDTSplashAd alloc] initWithAppkey: YOUR_APP_ID placementId: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 loadAdAndShowInWindow:self.window];
//设置开屏底部自定义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];
****这里有个坑,就是GDTSplashAd *splash不能这样创建一个GDTSplashAd临时变量,而必须将splash定义成一个strong属性变量:
@property (strong, nonatomic) GDTSplashAd *splash;
否则会发现,可以加载开屏广告,但回调事件不正常,广告加载,计时归零后不会自动消失;同时也无法点击广告;