1. 包含头文件
#import <UNAD/UNAD.h>
2. UNADSplash的创建和初始化
在Adelegate头文件中导入头文件并声明实例以及声明代理,(开屏需要在AppDelegate中实现,如在其他页面创建可能会出现落地页无法弹出的问题,或者在启动时不会销毁掉的VC里)
#import <UNAD/UNAD.h>
@interface AppDelegate ()<UNADSplashDelegate>
@property (nonatomic, strong) UNADSplash *adgSplash;
@end
创建和初始化广告,广告是异步的,所以不需要修改APP原有逻辑,初始化广告的方法放到
[self.window makeKeyAndVisible];
之后进行初始化
//初始化开屏广告 ,lifeTime 为超时秒数。
- (void)initAd{
self.splash = [[UNADSplash alloc]initWithUnitID:UNAD_TEST_UNIT_ID lifeTime:10];
self.splash.delegate = self;
}
显示广告
//开屏广告初始化并展示代码
- (void)loadAd {
UIImage *splashImage = [UIImage imageNamed:@"launchbg"];
self.splash.backgroundImage = splashImage;
[self.splash loadAndShow:self.window.rootViewController]
}
如果需要设置底部的logoView可以调用相应的代理详细代码参考Demo
3. UNADSplash 主要属性和方法说明
/**
开屏广告的背景图片
可以设置背景图片作为开屏加载时的默认背景
*/
@property (nonatomic, strong) UIImage *backgroundImage;
4.UNADSplashDelegate
//倒记时模式显示底部自定义内容
- (UIView *)splashBottomView
{
// return nil;
CGFloat logoHeight = 60;
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, logoHeight)];
bottomView.backgroundColor = [UIColor whiteColor];
UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SplashLogo"]];
logo.accessibilityIdentifier = @"splash_logo";
logo.frame = CGRectMake(0, 0, 311, 47);
logo.center = bottomView.center;
[bottomView addSubview:logo];
return bottomView;
}
/**
广告已加载
*/
- (void)splashAdDidLoad:(UNADSplash *)splash {
_statusLabel.text = @"广告已加载";
}
/**
开屏展现
*/
- (void)splashDidPresentScreen:(UNADSplash *)splash;
{
NSLog(@"开屏展现广告");
}
/**
开屏消失
*/
- (void)splashDidDismissScreen:(UNADSplash *)splash;
{
NSLog(@"开屏消失");
}
/**
开屏点击
*/
- (void)splashDidClick:(UNADSplash *)splash
{
NSLog(@"广告点击了");
}
/**
开屏请求失败
*/
- (void)splash:(UNADSplash *)splash didFailWithError:(NSError *)error;
{
NSLog(@"广告请求失败");
}