-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGADExpressManager.m
64 lines (51 loc) · 1.98 KB
/
GADExpressManager.m
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// GADExpressManager.m
// PrivacyPhoto
//
// Created by 冯 传祥 on 2017/6/10.
// Copyright © 2017年 冯 传祥. All rights reserved.
//
#import "GADExpressManager.h"
@import GoogleMobileAds;
@interface GADExpressManager () <GADNativeExpressAdViewDelegate, GADVideoControllerDelegate>
@end
@implementation GADExpressManager
- (instancetype)initWithFrame:(CGRect)frame
controller:(UIViewController *)controller
adUnitID:(NSString *)adUnitID
edgeInsets:(UIEdgeInsets)edgeInsets
{
self = [super initWithFrame:frame];
if (self) {
//360 * 320
CGRect adFrame = CGRectMake(edgeInsets.left, edgeInsets.top, frame.size.width - edgeInsets.left - edgeInsets.right, frame.size.height - edgeInsets.top - edgeInsets.bottom);
GADNativeExpressAdView *adView = [[GADNativeExpressAdView alloc]
initWithAdSize:GADAdSizeFromCGSize(adFrame.size) origin:adFrame.origin];
// adView.adUnitID = @"ca-app-pub-5190734310507136/8304096003";
adView.adUnitID = adUnitID;
adView.rootViewController = controller;
adView.delegate = self;
[self addSubview:adView];
GADRequest *request = [GADRequest request];
#ifdef DEBUG
request.testDevices = @[ kGADSimulatorID, @"f8bb43a77f9144ab3000965d8f795a2b"];
#endif
[adView loadRequest:request];
}
return self;
}
#pragma mark - GADNativeExpressAdViewDelegate, GADVideoControllerDelegate
- (void)nativeExpressAdViewDidReceiveAd:(GADNativeExpressAdView *)nativeExpressAdView {
if (_finishHandle) {
_finishHandle();
}
}
- (void)nativeExpressAdView:(GADNativeExpressAdView *)nativeExpressAdView
didFailToReceiveAdWithError:(GADRequestError *)error {
// Load the next ad in the adsToLoad list.
// [self preloadNextAd];
}
#pragma mark - GADVideoControllerDelegate
- (void)videoControllerDidEndVideoPlayback:(GADVideoController *)videoController {
}
@end