前提条件
接入UNADSDK
初始化UNADSDK
激励视频广告
1.添加头文件并实现代理接口
#import <UNAD/UNAD.h>
@interface RewardedViewController ()<UNADRewardedAdDelegate>
2.添加⼀个UNADRewardedAd的属性
@property(nonatomic, strong) UNADRewardedAd *rewardedAd;
3.创建激励视频广告对象并加载广告
self.rewardedAd = [[UNADRewardedAd alloc]initWithUnitID:UNAD_TEST_UNIT_ID];
self.rewardedAd.delegate = self;
[self.rewardedAd loadAd];
4.实现delegate方法,监听广告状态
- (void)rewardedAdLoaded:(UNADRewardedAd *)rewardedAd
{
_statusLabel.text = @"广告已经加载";
}
- (void)rewardedAd:(UNADRewardedAd *)rewardedAd didFailWithError:(NSError *)error
{
NSString *message = [ NSString stringWithFormat:@"广告加载失败:%@",error.localizedDescription];
_statusLabel.text = message;
}
- (void)rewardedAdShown:(UNADRewardedAd *)rewardedAd
{
_statusLabel.text = @"广告显示了";
}
- (void)rewardedAdClicked:(UNADRewardedAd *)rewardedAd
{
_statusLabel.text = @"广告被点击";
}
- (void)rewardedAdDismissed:(UNADRewardedAd *)rewardedAd
{
_statusLabel.text = @"广告已关闭,请重新加载";
}
//have reward
- (void)rewardedAdShouldRewardAd:(UNADRewardedAd *)rewardedAd
{
_statusLabel.text = @"获得奖励";
}
5.展示广告
[self.rewardedAd showAdFromRootViewController:self];