播放激励视频广告
业务场景
游戏集成激励广告功能,用于显示激励广告;
流程图
无
接口介绍
/**
* 激励视频广告--显示激励视频广告
*/
- (void)showRewardedAd:(RewardVideoInfo *)rewardVideoInfo;
调用示例
// 监听开启消息回调通知
// 广告播放成功
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onRewardedAdPlayFinished:)
name:NOTIFICATION_REWARDEDAD_PLAY_FINISHED
object:nil];
// 广告播放失败
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onRewardedAdPlayFailed:)
name:NOTIFICATION_REWARDEDAD_PLAY_FAILED
object:nil];
// 广告点击
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onRewardedAdSkipped:)
name:NOTIFICATION_REWARDEDAD_SKIPPED
object:nil];
// 播放激励广告
RewardVideoInfo *rewardVideoInfo = [[RewardVideoInfo alloc] init];
rewardVideoInfo.adUnitId = @"xxxxxxxx"; // 广告位ID
rewardVideoInfo.adType = 0; // 广告类型
rewardVideoInfo.adSceneTag = @""; // 广告位标签
[SDKManager.getInstance showRewardedAd:rewardVideoInfo];
// 回调方法
- (void)onRewardedAdPlayFinished:(NSNotification *)notif
{
NSDictionary *userDic = notif.userInfo;
NSString *adUnitId = [userDic objectForKey:KEY_ADUNITID];
NSString *adSceneTag = [userDic objectForKey:KEY_ADSCENETAG];
// 激励视频播放完成
}
- (void)onRewardedAdPlayFailed:(NSNotification *)notif
{
NSDictionary *errorInfo = notif.userInfo;
NSInteger errorCode = [[errorInfo objectForKey:KEY_ERROR_CODE] integerValue];
NSString *errorMsg = [errorInfo objectForKey:KEY_ERROR_MSG];
NSString *tip = [NSString stringWithFormat:@"激励广告播放失败 - errorCode = %ld -- errorMsg = %@", errorCode, errorMsg];
[self textViewLog:tip];
// 激励视频加载失败
// 游戏提示玩家失败,让玩家自行重试
}
- (void)onRewardedAdSkipped:(NSNotification *)notif
{
NSString *tip = [NSString stringWithFormat:@"激励广告点击"];
[self textViewLog:tip];
}
参数说明
入参 RewardVideoInfo rewardVideoInfo
参数名称 | 类型 | 说明 | 必传/可选 |
---|---|---|---|
rewardVideoInfo | RewardVideoInfo | 激励视频广告参数 RewardVideoInfo | 必传 |
错误码
无
FAQ
无