跳至主要內容

Draw视频流广告

大约 3 分钟

Draw视频流广告

概述

YTDrawVideoAdManager 属性及方法介绍

属性说明是否必填
adSize广告尺寸
delegate
enableShake是否允许摇一摇广告,默认YES可选
方法说明
- (instancetype)initWithSlotId:(NSString *)slotId构造方法,slotId不能为空
- (void)loadAd加载广告

YTDrawVideoAdManagerDelegate 代理方法介绍

@protocol YTDrawVideoAdManagerDelegate <NSObject>

@optional

/// 加载Draw流渲染广告成功
/// - Parameters:
///   - manager: manager
///   - drawVideoView: Draw广告对象
- (void)yt_drawVideoAdManager:(YTDrawVideoAdManager *) manager loadSuccess:(YTDrawVideoView *)drawVideoView;

/// drawVideo广告加载失败
- (void)yt_drawVideoAdManager:(YTDrawVideoAdManager *)drawVideoView didFailWithError:(NSError * _Nullable)error;

@end

YTDrawVideoView 属性及方法

属性说明是否必填
delegate必填
viewController所在的viewController,用于点击事件的跳转等,弱引用必填
videoMuted广告中的视频是否静音,默认静音可选
adInfo获取广告素材基本信息只读
方法声明
- (BOOL) isReady;
- (void) render;
- (void)destroyDrawVideoView;销毁广告

YTNativeExpressAdDelegate 方法介绍

@protocol YTDrawVideoAdViewDelegate <NSObject>
@optional
/// draw流view渲染成功
- (void)yt_drawVideoAdRenderSuccess:(YTDrawVideoView *)adView;

/// draw流view渲染失败
- (void)yt_drawVideoRenderAdView:(YTDrawVideoView *)adView didFailWithError:(NSError *_Nullable)error;

// draw流播放器异常错误信息
- (void)yt_drawVideoAdView:(YTDrawVideoView *)adView playerFailWithError:(NSError *_Nullable)error;

/// draw流view即将展示
- (void)yt_drawVideoAdViewWillShow:(YTDrawVideoView *)adView;

/// draw流view被关闭
- (void)yt_drawVideoAdViewDidClose:(YTDrawVideoView *)adView;

/// draw流view被曝光
- (void)yt_drawVideoAdViewDidExposed:(YTDrawVideoView *)adView;

/// 点击了draw流广告
- (void)yt_drawVideoViewDidClick:(YTDrawVideoView *)drawVideoView;

/// draw流视频播放状态发生变化
/// - Parameters:
///   - playerControlStatus: 当前只有正在播放和暂停两种状态回调
- (void)yt_drawVideoAdView:(YTDrawVideoView *)adView playerControlStatusDidChange:(YTPlayerControlStatus)playerControlStatus;

/// 展示AppStore或落地页
- (void)yt_drawVideoAdViewDidShowOtherController:(YTDrawVideoView *)adView;

/// 关闭AppStore或落地页
- (void)yt_drawVideoAdViewDidCloseOtherController:(YTDrawVideoView *)adView;

@end

接入示例

@interface YTDrawVideoViewController ()<UITableViewDelegate, UITableViewDataSource, YTDrawVideoAdManagerDelegate,YTDrawVideoAdViewDelegate>
@property (nonatomic, strong) YTDrawVideoAdManager *adManager;
@property (nonatomic, strong) YTDrawVideoView* adView;
@property (nonatomic, strong) UITableView *tableView;

- (void)loadAd:(NSString*)slotId {
    _adManager = [[YTDrawVideoAdManager alloc] initWithSlotId:slotId];
    _adManager.adSize = _adSize;
    _adManager.delegate = self;
    _adManager.enableShake = _enableShakeSwitch.on;
    _adManager.videoMuted = NO;
    [_adManager loadAd];
} 

- (void)drawVideoViewRender:(YTDrawVideoView*)drawVideoView {
    if ([drawVideoView isReady]) {
        drawVideoView.delegate = self;
        drawVideoView.viewController = self;
        drawVideoView.videoMuted = self.enableMuteSwitch.isOn;
        [drawVideoView render];
    }
}

#pragma mark - YTDrawVideoAdManagerDelegate
- (void)yt_drawVideoAdManager:(YTDrawVideoAdManager *) manager loadSuccess:(YTDrawVideoView*)drawVideoView {
    self.adView = drawVideoView;
    YTPageItem *adItem = [YTPageItem new];
    adItem.type = YTPageItemTypeAd;
    adItem.color = UIColor.clearColor;
    adItem.drawView = drawVideoView;
    [self.items addObject:adItem];
}

/// 广告报错
- (void)yt_drawVideoAdManager:(YTDrawVideoView *)adView didFailWithError:(NSError *_Nullable)error {
}

#pragma mark - YTDrawVideoAdViewDelegate
/// draw流view渲染成功
- (void)yt_drawVideoAdRenderSuccess:(YTDrawVideoView *)adView {
}

- (void)yt_drawVideoRenderAdView:(YTDrawVideoView *)adView didFailWithError:(NSError *_Nullable)error {
}

- (void)yt_drawVideoAdViewWillShow:(YTDrawVideoView *)adView {
}

// 广告曝光
- (void)yt_drawVideoAdViewDidExposed:(YTDrawVideoView *)adView {
}

/// 点击了draw流广告
- (void)yt_drawVideoViewDidClick:(YTDrawVideoView *)drawVideoView {
}

/// 展示AppStore或落地页
- (void)yt_drawVideoAdViewDidShowOtherController:(YTDrawVideoView *)adView {
}

/// 关闭AppStore或落地页
- (void)yt_drawVideoAdViewDidCloseOtherController:(YTDrawVideoView *)adView {
}

/// 关闭
- (void)yt_drawVideoAdViewDidClose:(YTDrawVideoView *)adView {
    [adView removeFromSuperview];
}

- (void)yt_drawVideoAdView:(YTDrawVideoView *)adView playerFailWithError:(NSError *_Nullable)error {
}

#pragma mark - YTNativeAdVideoPlayerViewDelegate
- (void)yt_drawVideoAdView:(YTDrawVideoView *)adView playerControlStatusDidChange:(YTPlayerControlStatus)playerControlStatus {
    NSString *playStatus = @"";
    switch (playerControlStatus) {
        case YTPlayerControlStatusReady:
            playStatus = @"播放准备就绪";
            break;
        case YTPlayerControlStatusPlaying:
            playStatus = @"正在播放";
            break;
        case YTPlayerControlStatusPaused:
            playStatus = @"暂停";
            break;
        case YTPlayerControlStatusFinish:
            playStatus = @"完毕";
            break;
        default:
            playStatus = @"unknown";
            break;
    }
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section {
    return self.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YTPageItem *item = self.items[indexPath.row];
    YTDrawTableViewCell *cell =
        [tableView dequeueReusableCellWithIdentifier:@"YTDrawTableViewCell"
                                        forIndexPath:indexPath];

    cell.contentView.backgroundColor = item.color;
    return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    YTPageItem *item = self.items[indexPath.row];
    YTDrawTableViewCell *pcell = (YTDrawTableViewCell*)cell;
    if (item.type == YTPageItemTypeAd) {
        [pcell attachAdView:item.drawView];
    } else {
        [pcell detachAdView];
    }
}

#pragma mark - UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    // 每一页高度 = tableView 可视高度
    return tableView.bounds.size.height;
}
@end
上次编辑于: