-
Notifications
You must be signed in to change notification settings - Fork 1
/
FBAudienceNetwork+Convenience.m
82 lines (62 loc) · 2.29 KB
/
FBAudienceNetwork+Convenience.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// FBAdView+Convenience.m
// Ringtonic
//
// Created by Alexander Ivanov on 09.11.16.
// Copyright © 2016 Alexander Ivanov. All rights reserved.
//
#import "FBAudienceNetwork+Convenience.h"
@implementation FBAdView (Convenience)
+ (instancetype)loadWithPlacementID:(NSString *)placementID rootViewController:(UIViewController *)viewController {
FBAdView *adView = [[self alloc] initWithPlacementID:placementID adSize:(viewController ? viewController.iPad : [UIApplication sharedApplication].iPad) ? kFBAdSizeHeight90Banner : kFBAdSizeHeight50Banner rootViewController:viewController];
[adView loadAd];
return adView;
}
+ (instancetype)loadWithPlacementID:(NSString *)placementID {
return [self loadWithPlacementID:placementID rootViewController:Nil];
}
@end
@interface FBAdViewDelegate ()
@property (copy, nonatomic) void(^completion)(FBAdView *adView);
@property (strong, nonatomic) FBAdView *adView;
@end
@implementation FBAdViewDelegate
- (FBAdSize)adSize {
return [UIApplication sharedApplication].iPad ? kFBAdSizeHeight90Banner : kFBAdSizeHeight50Banner;
}
- (instancetype)init {
self = [super init];
if (self) {
// if (IS_DEBUGGING)
// [FBAdSettings addTestDevice:[FBAdSettings testDeviceHash]];
// else
[FBAdSettings clearTestDevices];
}
return self;
}
- (FBAdView *)loadWithPlacementID:(NSString *)placementID rootViewController:(UIViewController *)viewController completion:(void (^)(FBAdView *adView))completion {
self.adView = [[FBAdView alloc] initWithPlacementID:placementID adSize:viewController ? viewController.iPad ? kFBAdSizeHeight90Banner : kFBAdSizeHeight50Banner : self.adSize rootViewController:viewController];
self.completion = completion;
self.adView.delegate = self;
[self.adView loadAd];
return self.adView;
}
- (FBAdView *)loadWithPlacementID:(NSString *)placementID completion:(void (^)(FBAdView *adView))completion {
return [self loadWithPlacementID:placementID rootViewController:nil completion:completion];
}
- (void)adViewDidLoad:(FBAdView *)adView {
self.adView = Nil;
if (self.completion) {
self.completion(adView);
self.completion = Nil;
}
}
- (void)adView:(FBAdView *)adView didFailWithError:(NSError *)error {
self.adView = Nil;
if (self.completion) {
self.completion(Nil);
self.completion = Nil;
}
[error log:@"adView:didFailWithError:"];
}
@end