# 3.激励视频
# 导入头文件
集成激励视频广告,需要导入以下头文件:
#import <HXADSDK/HXADSDK.h>
1
# 请求广告
请求广告时,需传入对应的代理对象,用来处理广告加载完成后的展示及其他操作。
+ (void)loadVideoWithDelegate:(nullable id <HXRewardAdLoadDelegate>)delegate;
1
示例代码:
#import "ViewController.h"
#import <HXADSDK/HXADSDK.h>
@interface ViewController ()<HXRewardAdLoadDelegate,HXRewardAdShowDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)click:(id)sender{
[HXRewardAd loadVideoWithDelegate:self];
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 请求广告回调
@protocol HXRewardAdLoadDelegate <NSObject>
@optional
/** 广告加载成功,需等待加载完毕 */
- (void)onAdLoadSuccess;
/** 广告已成功加载,可以展示 */
- (void)onVideoAdLoadSuccess;
/** 广告加载失败 */
- (void)onVideoAdLoadFailedError:(nonnull NSError *)error;
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
示例代码:
#pragma mark -HXRewardAdLoadDelegate
- (void)onAdLoadSuccess{
NSLog(@"广告加载成功,需等待加载完毕");
}
- (void)onVideoAdLoadSuccess{
NSLog(@"广告已成功加载,可以展示");
}
- (void)onVideoAdLoadFailedError:(nonnull NSError *)error{
NSLog(@"广告加载失败");
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 展示广告
实现协议判断广告是否已经下载成功,如果视频可以播放SDK会返回成功信息,然后调用展示方法展示视频广告;如果返回失败,就放弃这次视频展示机会。
/**
* 展示广告
*
* @param delegate -代理对象
* @param viewController - 将要展示的广告的根视图控制器
*/
+ (BOOL)showVideoWithDelegate:(nullable id <HXRewardAdShowDelegate>)delegate
viewController:(nonnull UIViewController*)viewController;
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
示例代码:
#import "ViewController.h"
#import <HXADSDK/HXADSDK.h>
@interface ViewController ()<HXRewardAdLoadDelegate,HXRewardAdShowDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)click:(id)sender{
[HXRewardAd loadVideoWithDelegate:self];
}
- (void)onAdLoadSuccess{
NSLog(@"%s",__FUNCTION__);
}
/**
* Called when the ad is successfully load , and is ready to be displayed
*/
- (void)onVideoAdLoadSuccess{
NSLog(@"%s",__FUNCTION__);
[HXRewardAd showVideoWithDelegate:self viewController:self];
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 展示广告回调
@protocol HXRewardAdShowDelegate <NSObject>
@optional
/** 广告展示成功 */
- (void)onVideoAdShowSuccess;
/** 广告展示失败 */
- (void)onVideoAdShowFailedError:(nonnull NSError *)error;
/** 广告播放完毕 */
- (void) onVideoPlayCompleted;
/** 在广告包含尾卡内容时调用,并在显示尾卡时调用 */
- (void) onVideoEndCardShowSuccess;
/** 广告被点击 */
- (void)onVideoAdClicked;
/** 广告被点击关闭按钮 */
- (void)onVideoAdDismissed;
/** 广告被关闭 */
- (void)onVideoAdDidClosed;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
示例代码:
#pragma mark -HXRewardAdShowDelegate
- (void)onVideoAdShowSuccess{
NSLog(@"广告展示成功");
}
- (void)onVideoAdShowFailedError:(nonnull NSError *)error{
NSLog(@"广告展示失败");
}
- (void) onVideoPlayCompleted{
NSLog(@"广告播放完毕");
}
- (void) onVideoEndCardShowSuccess{
NSLog(@"在广告包含尾卡内容时调用,并在显示尾卡时调用");
}
- (void)onVideoAdClicked{
NSLog(@"广告被点击");
}
- (void)onVideoAdDismissed{
NSLog(@"广告被点击关闭按钮");
}
- (void)onVideoAdDidClosed{
NSLog(@"广告被关闭");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
← 2.开屏广告