cordova-plugin-admob-nextgen 1.7.9 → 1.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/ios/AdMobNextGen.m +63 -2
- package/src/ios/AppOpenAdExecutor.m +5 -0
- package/src/ios/BannerExecutor.m +309 -194
- package/src/ios/InterstitialExecutor.m +4 -1
- package/src/ios/RewardedExecutor.m +4 -1
- package/src/ios/RewardedInterstitialExecutor.m +4 -5
package/README.md
CHANGED
|
@@ -17,6 +17,8 @@ It moves away from legacy implementations to modern `SurfaceControl`, optimized
|
|
|
17
17
|
|
|
18
18
|
> **Maintained by the original creator of [EMI-INDO/emi-indo-cordova-plugin-admob](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob).** This is not just an update; it is a brand new engine designed for 2026 and beyond.
|
|
19
19
|
|
|
20
|
+
---
|
|
21
|
+
> (NEW) ⚡️ Next-Gen special capacitor: [capacitor-admob-nextgen](https://github.com/swaplab-engine/capacitor-admob-nextgen)
|
|
20
22
|
---
|
|
21
23
|
|
|
22
24
|
## 🚀 Why Next-Gen?
|
package/package.json
CHANGED
package/plugin.xml
CHANGED
package/src/ios/AdMobNextGen.m
CHANGED
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
#import "RewardedInterstitialExecutor.h"
|
|
9
9
|
|
|
10
10
|
@interface AdMobNextGen()
|
|
11
|
+
@property (nonatomic, assign) BOOL isInitialized;
|
|
11
12
|
@property (nonatomic, strong) ConsentExecutor *consentExecutor;
|
|
12
13
|
@property (nonatomic, strong) GlobalSettingsExecutor *globalSettingsExecutor;
|
|
13
14
|
@property (nonatomic, strong) BannerExecutor *bannerExecutor;
|
|
14
|
-
@property (nonatomic, strong) InterstitialExecutor *interstitialExecutor;
|
|
15
|
+
@property (nonatomic, strong) InterstitialExecutor *interstitialExecutor;
|
|
15
16
|
@property (nonatomic, strong) RewardedExecutor *rewardedExecutor;
|
|
16
17
|
@property (nonatomic, strong) RewardedInterstitialExecutor *rewardedInterstitialExecutor;
|
|
17
18
|
@end
|
|
@@ -23,15 +24,50 @@
|
|
|
23
24
|
self.consentExecutor = [[ConsentExecutor alloc] initWithPlugin:self];
|
|
24
25
|
self.globalSettingsExecutor = [[GlobalSettingsExecutor alloc] initWithPlugin:self];
|
|
25
26
|
self.bannerExecutor = [[BannerExecutor alloc] initWithPlugin:self];
|
|
26
|
-
self.interstitialExecutor = [[InterstitialExecutor alloc] initWithPlugin:self];
|
|
27
|
+
self.interstitialExecutor = [[InterstitialExecutor alloc] initWithPlugin:self];
|
|
27
28
|
self.rewardedExecutor = [[RewardedExecutor alloc] initWithPlugin:self];
|
|
28
29
|
[[AppOpenAdExecutor sharedInstance] initializeWithPlugin:self];
|
|
29
30
|
self.rewardedInterstitialExecutor = [[RewardedInterstitialExecutor alloc] initWithPlugin:self];
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
- (void)initialize:(CDVInvokedUrlCommand*)command {
|
|
34
|
+
NSDictionary *options = nil;
|
|
35
|
+
if (command.arguments.count > 0 && [command.arguments objectAtIndex:0] != [NSNull null]) {
|
|
36
|
+
options = [command.arguments objectAtIndex:0];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (options != nil && [options isKindOfClass:[NSDictionary class]]) {
|
|
40
|
+
GADRequestConfiguration *requestConfig = GADMobileAds.sharedInstance.requestConfiguration;
|
|
41
|
+
|
|
42
|
+
if (options[@"maxAdContentRating"]) {
|
|
43
|
+
NSString *rating = options[@"maxAdContentRating"];
|
|
44
|
+
if ([rating isEqualToString:@"G"]) {
|
|
45
|
+
requestConfig.maxAdContentRating = GADMaxAdContentRatingGeneral;
|
|
46
|
+
} else if ([rating isEqualToString:@"PG"]) {
|
|
47
|
+
requestConfig.maxAdContentRating = GADMaxAdContentRatingParentalGuidance;
|
|
48
|
+
} else if ([rating isEqualToString:@"T"]) {
|
|
49
|
+
requestConfig.maxAdContentRating = GADMaxAdContentRatingTeen;
|
|
50
|
+
} else if ([rating isEqualToString:@"MA"]) {
|
|
51
|
+
requestConfig.maxAdContentRating = GADMaxAdContentRatingMatureAudience;
|
|
52
|
+
} else {
|
|
53
|
+
requestConfig.maxAdContentRating = @"";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (options[@"tagForChildDirectedTreatment"]) {
|
|
58
|
+
BOOL isChildDirected = [options[@"tagForChildDirectedTreatment"] boolValue];
|
|
59
|
+
requestConfig.tagForChildDirectedTreatment = @(isChildDirected);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (options[@"tagForUnderAgeOfConsent"]) {
|
|
63
|
+
BOOL isUnderAge = [options[@"tagForUnderAgeOfConsent"] boolValue];
|
|
64
|
+
requestConfig.tagForUnderAgeOfConsent = @(isUnderAge);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
33
68
|
[self.commandDelegate runInBackground:^{
|
|
34
69
|
[[GADMobileAds sharedInstance] startWithCompletionHandler:^(GADInitializationStatus * _Nonnull status) {
|
|
70
|
+
self.isInitialized = YES;
|
|
35
71
|
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Initialization complete."];
|
|
36
72
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
37
73
|
}];
|
|
@@ -85,6 +121,11 @@
|
|
|
85
121
|
#pragma mark - Banner Routing
|
|
86
122
|
|
|
87
123
|
- (void)createBanner:(CDVInvokedUrlCommand*)command {
|
|
124
|
+
if (!self.isInitialized) {
|
|
125
|
+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"SDK not initialized. Call initialize() first."];
|
|
126
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
88
129
|
NSDictionary *options = [command.arguments objectAtIndex:0];
|
|
89
130
|
if (options != nil && [options isKindOfClass:[NSDictionary class]]) {
|
|
90
131
|
[self.bannerExecutor createBanner:options command:command];
|
|
@@ -109,6 +150,11 @@
|
|
|
109
150
|
#pragma mark - Interstitial Routing
|
|
110
151
|
|
|
111
152
|
- (void)createInterstitial:(CDVInvokedUrlCommand*)command {
|
|
153
|
+
if (!self.isInitialized) {
|
|
154
|
+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"SDK not initialized. Call initialize() first."];
|
|
155
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
112
158
|
NSDictionary *options = [command.arguments objectAtIndex:0];
|
|
113
159
|
if (options != nil && [options isKindOfClass:[NSDictionary class]]) {
|
|
114
160
|
[self.interstitialExecutor createInterstitial:options command:command];
|
|
@@ -123,6 +169,11 @@
|
|
|
123
169
|
}
|
|
124
170
|
|
|
125
171
|
- (void)createRewarded:(CDVInvokedUrlCommand*)command {
|
|
172
|
+
if (!self.isInitialized) {
|
|
173
|
+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"SDK not initialized. Call initialize() first."];
|
|
174
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
126
177
|
NSDictionary *options = [command.arguments objectAtIndex:0];
|
|
127
178
|
if (options != nil) {
|
|
128
179
|
[self.rewardedExecutor createRewarded:options command:command];
|
|
@@ -134,6 +185,11 @@
|
|
|
134
185
|
}
|
|
135
186
|
|
|
136
187
|
- (void)loadAppOpenAd:(CDVInvokedUrlCommand*)command {
|
|
188
|
+
if (!self.isInitialized) {
|
|
189
|
+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"SDK not initialized. Call initialize() first."];
|
|
190
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
137
193
|
NSDictionary *options = [command.arguments objectAtIndex:0];
|
|
138
194
|
if (options != nil) {
|
|
139
195
|
[[AppOpenAdExecutor sharedInstance] loadAppOpenAd:options command:command];
|
|
@@ -145,6 +201,11 @@
|
|
|
145
201
|
}
|
|
146
202
|
|
|
147
203
|
- (void)createRewardedInterstitial:(CDVInvokedUrlCommand*)command {
|
|
204
|
+
if (!self.isInitialized) {
|
|
205
|
+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"SDK not initialized. Call initialize() first."];
|
|
206
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
148
209
|
NSDictionary *options = [command.arguments objectAtIndex:0];
|
|
149
210
|
if (options != nil) {
|
|
150
211
|
[self.rewardedInterstitialExecutor createRewardedInterstitial:options command:command];
|
|
@@ -84,6 +84,11 @@
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
if ((currentTime - self.lastLoadTime) < self.minLoadInterval) {
|
|
87
|
+
|
|
88
|
+
NSString *errorMsg = [NSString stringWithFormat:@"Request too fast. Please wait %.0fms to prevent invalid traffic.", (self.minLoadInterval * 1000.0)];
|
|
89
|
+
|
|
90
|
+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errorMsg];
|
|
91
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
87
92
|
return;
|
|
88
93
|
}
|
|
89
94
|
|
package/src/ios/BannerExecutor.m
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
#import "BannerExecutor.h"
|
|
2
2
|
#import "AdMobNextGen.h"
|
|
3
3
|
|
|
4
|
-
@interface BannerExecutor()
|
|
4
|
+
@interface BannerExecutor ()
|
|
5
5
|
|
|
6
|
-
@property
|
|
7
|
-
@property
|
|
6
|
+
@property(nonatomic, weak) AdMobNextGen *plugin;
|
|
7
|
+
@property(nonatomic, strong) GADBannerView *bannerView;
|
|
8
|
+
@property(nonatomic, strong) GADBannerView *pendingBannerView;
|
|
8
9
|
|
|
9
|
-
@property
|
|
10
|
-
@property
|
|
11
|
-
@property
|
|
12
|
-
@property
|
|
13
|
-
@property
|
|
10
|
+
@property(nonatomic, strong) NSString *lastAdUnitId;
|
|
11
|
+
@property(nonatomic, strong) NSString *lastSizeStr;
|
|
12
|
+
@property(nonatomic, strong) NSString *currentPosition;
|
|
13
|
+
@property(nonatomic, strong) NSString *lastPosition;
|
|
14
|
+
@property(nonatomic, assign) GADAdSize lastAdSize;
|
|
14
15
|
|
|
15
|
-
@property
|
|
16
|
-
@property
|
|
17
|
-
@property
|
|
18
|
-
@property
|
|
19
|
-
@property
|
|
16
|
+
@property(nonatomic, assign) BOOL isBannerVisible;
|
|
17
|
+
@property(nonatomic, assign) BOOL isLoading;
|
|
18
|
+
@property(nonatomic, assign) BOOL isOverlapping;
|
|
19
|
+
@property(nonatomic, assign) BOOL isAutoShow;
|
|
20
|
+
@property(nonatomic, assign) BOOL isCollapsible;
|
|
20
21
|
|
|
21
|
-
@property
|
|
22
|
+
@property(nonatomic, assign) CGFloat activeBannerHeight;
|
|
22
23
|
|
|
23
|
-
@property
|
|
24
|
-
@property
|
|
24
|
+
@property(nonatomic, assign) NSTimeInterval lastLoadTime;
|
|
25
|
+
@property(nonatomic, assign) NSTimeInterval minLoadInterval;
|
|
25
26
|
|
|
26
27
|
@end
|
|
27
28
|
|
|
@@ -47,10 +48,11 @@
|
|
|
47
48
|
self.lastLoadTime = 0;
|
|
48
49
|
self.minLoadInterval = 5.0;
|
|
49
50
|
|
|
50
|
-
[[NSNotificationCenter defaultCenter]
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
[[NSNotificationCenter defaultCenter]
|
|
52
|
+
addObserver:self
|
|
53
|
+
selector:@selector(layoutViews)
|
|
54
|
+
name:UIDeviceOrientationDidChangeNotification
|
|
55
|
+
object:nil];
|
|
54
56
|
}
|
|
55
57
|
return self;
|
|
56
58
|
}
|
|
@@ -59,92 +61,129 @@
|
|
|
59
61
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
#pragma mark - Smart Window Helper
|
|
64
|
+
#pragma mark - Smart Window Helper
|
|
63
65
|
|
|
64
66
|
- (UIWindow *)getKeyWindow {
|
|
65
67
|
UIWindow *window = nil;
|
|
66
68
|
if (@available(iOS 13.0, *)) {
|
|
67
|
-
for (UIWindowScene *windowScene in [UIApplication sharedApplication]
|
|
68
|
-
|
|
69
|
+
for (UIWindowScene *windowScene in [UIApplication sharedApplication]
|
|
70
|
+
.connectedScenes) {
|
|
71
|
+
if (windowScene.activationState ==
|
|
72
|
+
UISceneActivationStateForegroundActive) {
|
|
69
73
|
for (UIWindow *w in windowScene.windows) {
|
|
70
|
-
if (w.isKeyWindow) {
|
|
74
|
+
if (w.isKeyWindow) {
|
|
75
|
+
window = w;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
71
78
|
}
|
|
72
79
|
}
|
|
73
|
-
if (window)
|
|
80
|
+
if (window)
|
|
81
|
+
break;
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
84
|
if (!window) {
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
#pragma clang diagnostic push
|
|
86
|
+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
79
87
|
window = [UIApplication sharedApplication].keyWindow;
|
|
80
|
-
|
|
88
|
+
#pragma clang diagnostic pop
|
|
81
89
|
}
|
|
82
90
|
return window;
|
|
83
91
|
}
|
|
84
92
|
|
|
85
93
|
#pragma mark - Main Methods
|
|
86
94
|
|
|
87
|
-
- (void)createBanner:(NSDictionary *)options
|
|
95
|
+
- (void)createBanner:(NSDictionary *)options
|
|
96
|
+
command:(CDVInvokedUrlCommand *)command {
|
|
88
97
|
NSString *adUnitId = options[@"adUnitId"];
|
|
89
98
|
NSString *requestedSize = options[@"size"] ? options[@"size"] : @"ADAPTIVE";
|
|
90
|
-
NSString *newPosition =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
BOOL
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
NSString *newPosition =
|
|
100
|
+
options[@"position"] ? options[@"position"] : self.currentPosition;
|
|
101
|
+
|
|
102
|
+
BOOL newIsOverlapping =
|
|
103
|
+
options[@"isOverlapping"] ? [options[@"isOverlapping"] boolValue] : YES;
|
|
104
|
+
BOOL newIsAutoShow =
|
|
105
|
+
options[@"isAutoShow"] ? [options[@"isAutoShow"] boolValue] : YES;
|
|
106
|
+
BOOL newIsCollapsible =
|
|
107
|
+
options[@"collapsible"] ? [options[@"collapsible"] boolValue] : NO;
|
|
108
|
+
NSTimeInterval newMinLoadInterval =
|
|
109
|
+
options[@"retryInterval"]
|
|
110
|
+
? [options[@"retryInterval"] doubleValue] / 1000.0
|
|
111
|
+
: 5.0;
|
|
96
112
|
|
|
97
113
|
if (!adUnitId) {
|
|
98
|
-
CDVPluginResult*
|
|
99
|
-
|
|
114
|
+
CDVPluginResult *pluginResult =
|
|
115
|
+
[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
|
|
116
|
+
messageAsString:@"adUnitId is required."];
|
|
117
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult
|
|
118
|
+
callbackId:command.callbackId];
|
|
100
119
|
return;
|
|
101
120
|
}
|
|
102
121
|
|
|
103
122
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
123
|
+
NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970];
|
|
124
|
+
|
|
125
|
+
if (self.isLoading) {
|
|
126
|
+
CDVPluginResult *pluginResult =
|
|
127
|
+
[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
|
|
128
|
+
messageAsString:@"Banner loading"];
|
|
129
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult
|
|
130
|
+
callbackId:command.callbackId];
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
BOOL isSameId = [self.lastAdUnitId isEqualToString:adUnitId];
|
|
135
|
+
BOOL isSameSize = [self.lastSizeStr isEqualToString:requestedSize];
|
|
136
|
+
|
|
137
|
+
self.isOverlapping = newIsOverlapping;
|
|
138
|
+
self.isAutoShow = newIsAutoShow;
|
|
139
|
+
self.isCollapsible = newIsCollapsible;
|
|
140
|
+
self.minLoadInterval = newMinLoadInterval;
|
|
141
|
+
self.currentPosition = newPosition;
|
|
142
|
+
|
|
143
|
+
if (self.bannerView != nil && isSameId && isSameSize) {
|
|
144
|
+
if (self.isAutoShow) {
|
|
145
|
+
[self showBannerInternal];
|
|
146
|
+
CDVPluginResult *pluginResult =
|
|
147
|
+
[CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
148
|
+
messageAsString:@"Banner Updated (Cached)"];
|
|
149
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult
|
|
150
|
+
callbackId:command.callbackId];
|
|
151
|
+
} else {
|
|
152
|
+
[self hideBannerInternal];
|
|
153
|
+
CDVPluginResult *pluginResult =
|
|
154
|
+
[CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
155
|
+
messageAsString:@"Banner Hidden (Cached)"];
|
|
156
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult
|
|
157
|
+
callbackId:command.callbackId];
|
|
158
|
+
}
|
|
159
|
+
[self sendLoadedEvent:self.lastAdSize
|
|
160
|
+
isCollapsible:self.isCollapsible
|
|
161
|
+
isRefresh:NO];
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if ((currentTime - self.lastLoadTime) < self.minLoadInterval) {
|
|
166
|
+
NSString *errorMsg =
|
|
167
|
+
[NSString stringWithFormat:@"Request too fast. Please wait "
|
|
168
|
+
@"%.0fms to prevent invalid traffic.",
|
|
169
|
+
(self.minLoadInterval * 1000.0)];
|
|
170
|
+
|
|
171
|
+
CDVPluginResult *pluginResult =
|
|
172
|
+
[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
|
|
173
|
+
messageAsString:errorMsg];
|
|
174
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult
|
|
175
|
+
callbackId:command.callbackId];
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
self.lastPosition = self.currentPosition;
|
|
180
|
+
[self loadBanner:adUnitId size:requestedSize command:command];
|
|
143
181
|
});
|
|
144
182
|
}
|
|
145
183
|
|
|
146
|
-
- (void)loadBanner:(NSString *)adUnitId
|
|
147
|
-
|
|
184
|
+
- (void)loadBanner:(NSString *)adUnitId
|
|
185
|
+
size:(NSString *)sizeStr
|
|
186
|
+
command:(CDVInvokedUrlCommand *)command {
|
|
148
187
|
|
|
149
188
|
self.isLoading = YES;
|
|
150
189
|
self.lastLoadTime = [[NSDate date] timeIntervalSince1970];
|
|
@@ -156,110 +195,131 @@
|
|
|
156
195
|
GADAdSize adSize = [self getAdSize:sizeStr];
|
|
157
196
|
self.lastAdSize = adSize;
|
|
158
197
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
self.bannerView.hidden = YES;
|
|
198
|
+
GADBannerView *pendingView = [[GADBannerView alloc] initWithAdSize:adSize];
|
|
199
|
+
pendingView.adUnitID = adUnitId;
|
|
200
|
+
pendingView.rootViewController = rootViewController;
|
|
201
|
+
pendingView.delegate = self;
|
|
202
|
+
pendingView.hidden = YES;
|
|
165
203
|
|
|
166
204
|
__weak typeof(self) weakSelf = self;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
205
|
+
pendingView.paidEventHandler = ^(GADAdValue *_Nonnull value) {
|
|
206
|
+
NSString *jsonStr = [NSString
|
|
207
|
+
stringWithFormat:
|
|
208
|
+
@"{\"value\":%lld, \"currency\":\"%@\", \"precision\":%ld}",
|
|
209
|
+
value.value.longLongValue, value.currencyCode,
|
|
210
|
+
(long)value.precision];
|
|
211
|
+
[weakSelf.plugin fireEvent:@"document"
|
|
212
|
+
event:@"on.banner.revenue"
|
|
213
|
+
withData:jsonStr];
|
|
171
214
|
};
|
|
172
215
|
|
|
173
|
-
|
|
216
|
+
self.pendingBannerView = pendingView;
|
|
217
|
+
[rootViewController.view addSubview:self.pendingBannerView];
|
|
174
218
|
|
|
175
219
|
GADRequest *request = [GADRequest request];
|
|
176
220
|
|
|
177
221
|
if (self.isCollapsible) {
|
|
178
222
|
GADExtras *extras = [[GADExtras alloc] init];
|
|
179
|
-
NSString *anchor =
|
|
180
|
-
|
|
223
|
+
NSString *anchor =
|
|
224
|
+
[self.currentPosition isEqualToString:@"top"] ? @"top" : @"bottom";
|
|
225
|
+
extras.additionalParameters = @{@"collapsible" : anchor};
|
|
181
226
|
[request registerAdNetworkExtras:extras];
|
|
182
227
|
}
|
|
183
228
|
|
|
184
|
-
[self.
|
|
229
|
+
[self.pendingBannerView loadRequest:request];
|
|
185
230
|
|
|
186
|
-
CDVPluginResult*
|
|
187
|
-
|
|
231
|
+
CDVPluginResult *pluginResult =
|
|
232
|
+
[CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
233
|
+
messageAsString:@"Banner creation initiated."];
|
|
234
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult
|
|
235
|
+
callbackId:command.callbackId];
|
|
188
236
|
}
|
|
189
237
|
|
|
190
238
|
- (GADAdSize)getAdSize:(NSString *)sizeStr {
|
|
191
|
-
if ([sizeStr isEqualToString:@"BANNER"])
|
|
192
|
-
|
|
193
|
-
if ([sizeStr isEqualToString:@"
|
|
194
|
-
|
|
195
|
-
if ([sizeStr isEqualToString:@"
|
|
239
|
+
if ([sizeStr isEqualToString:@"BANNER"])
|
|
240
|
+
return GADAdSizeBanner;
|
|
241
|
+
if ([sizeStr isEqualToString:@"LARGE_BANNER"])
|
|
242
|
+
return GADAdSizeLargeBanner;
|
|
243
|
+
if ([sizeStr isEqualToString:@"MEDIUM_RECTANGLE"])
|
|
244
|
+
return GADAdSizeMediumRectangle;
|
|
245
|
+
if ([sizeStr isEqualToString:@"FULL_BANNER"])
|
|
246
|
+
return GADAdSizeFullBanner;
|
|
247
|
+
if ([sizeStr isEqualToString:@"LEADERBOARD"])
|
|
248
|
+
return GADAdSizeLeaderboard;
|
|
196
249
|
|
|
197
250
|
UIViewController *rootViewController = self.plugin.viewController;
|
|
198
251
|
CGRect frame = rootViewController.view.frame;
|
|
199
252
|
if (@available(iOS 11.0, *)) {
|
|
200
|
-
frame = UIEdgeInsetsInsetRect(rootViewController.view.frame,
|
|
253
|
+
frame = UIEdgeInsetsInsetRect(rootViewController.view.frame,
|
|
254
|
+
rootViewController.view.safeAreaInsets);
|
|
201
255
|
}
|
|
202
|
-
return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(
|
|
256
|
+
return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(
|
|
257
|
+
frame.size.width);
|
|
203
258
|
}
|
|
204
259
|
|
|
205
260
|
- (void)layoutViews {
|
|
206
261
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
262
|
+
UIViewController *rootVC = self.plugin.viewController;
|
|
263
|
+
UIView *webView = self.plugin.webView;
|
|
264
|
+
if (!rootVC || !webView)
|
|
265
|
+
return;
|
|
266
|
+
|
|
267
|
+
UIWindow *window = [self getKeyWindow];
|
|
268
|
+
UIEdgeInsets safeArea =
|
|
269
|
+
(window) ? window.safeAreaInsets : UIEdgeInsetsZero;
|
|
270
|
+
|
|
271
|
+
CGFloat screenH = UIScreen.mainScreen.bounds.size.height;
|
|
272
|
+
CGFloat screenW = UIScreen.mainScreen.bounds.size.width;
|
|
273
|
+
|
|
274
|
+
if (safeArea.bottom == 0 && screenH >= 812.0)
|
|
275
|
+
safeArea.bottom = 34.0;
|
|
276
|
+
if (safeArea.top == 0 && screenH >= 812.0)
|
|
277
|
+
safeArea.top = 44.0;
|
|
278
|
+
|
|
279
|
+
CGRect fullScreenRect = CGRectMake(0, 0, screenW, screenH);
|
|
280
|
+
|
|
281
|
+
if (self.isBannerVisible && self.bannerView &&
|
|
282
|
+
self.activeBannerHeight > 0) {
|
|
283
|
+
|
|
284
|
+
CGSize adSize = self.bannerView.intrinsicContentSize;
|
|
285
|
+
CGFloat bH =
|
|
286
|
+
adSize.height > 0 ? adSize.height : self.activeBannerHeight;
|
|
287
|
+
CGFloat bW = adSize.width > 0 ? adSize.width
|
|
288
|
+
: self.bannerView.bounds.size.width;
|
|
289
|
+
CGFloat bX = (screenW - bW) / 2.0;
|
|
290
|
+
CGFloat bY = 0;
|
|
291
|
+
|
|
292
|
+
if ([self.currentPosition isEqualToString:@"top"]) {
|
|
293
|
+
bY = safeArea.top;
|
|
294
|
+
} else {
|
|
295
|
+
bY = screenH - safeArea.bottom - bH;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
self.bannerView.frame = CGRectMake(bX, bY, bW, bH);
|
|
299
|
+
self.bannerView.hidden = NO;
|
|
300
|
+
|
|
301
|
+
if (!self.isOverlapping) {
|
|
302
|
+
CGRect newWebFrame = fullScreenRect;
|
|
303
|
+
if ([self.currentPosition isEqualToString:@"top"]) {
|
|
304
|
+
newWebFrame.origin.y = bY + bH;
|
|
305
|
+
newWebFrame.size.height = screenH - newWebFrame.origin.y;
|
|
306
|
+
} else {
|
|
307
|
+
newWebFrame.origin.y = 0;
|
|
308
|
+
newWebFrame.size.height = bY;
|
|
309
|
+
}
|
|
310
|
+
webView.frame = newWebFrame;
|
|
311
|
+
} else {
|
|
312
|
+
webView.frame = fullScreenRect;
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
if (self.bannerView)
|
|
316
|
+
self.bannerView.hidden = YES;
|
|
317
|
+
webView.frame = fullScreenRect;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (self.bannerView && self.isBannerVisible) {
|
|
321
|
+
[webView.superview bringSubviewToFront:self.bannerView];
|
|
322
|
+
}
|
|
263
323
|
});
|
|
264
324
|
}
|
|
265
325
|
|
|
@@ -294,76 +354,131 @@
|
|
|
294
354
|
|
|
295
355
|
- (void)showBanner:(CDVInvokedUrlCommand *)command {
|
|
296
356
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
357
|
+
if (self.bannerView) {
|
|
358
|
+
[self showBannerInternal];
|
|
359
|
+
CDVPluginResult *pluginResult =
|
|
360
|
+
[CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
|
361
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult
|
|
362
|
+
callbackId:command.callbackId];
|
|
363
|
+
} else {
|
|
364
|
+
CDVPluginResult *pluginResult =
|
|
365
|
+
[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
|
|
366
|
+
messageAsString:@"No banner loaded"];
|
|
367
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult
|
|
368
|
+
callbackId:command.callbackId];
|
|
369
|
+
}
|
|
305
370
|
});
|
|
306
371
|
}
|
|
307
372
|
|
|
308
373
|
- (void)hideBanner:(CDVInvokedUrlCommand *)command {
|
|
309
374
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
375
|
+
[self hideBannerInternal];
|
|
376
|
+
CDVPluginResult *pluginResult =
|
|
377
|
+
[CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
|
378
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult
|
|
379
|
+
callbackId:command.callbackId];
|
|
313
380
|
});
|
|
314
381
|
}
|
|
315
382
|
|
|
316
383
|
- (void)removeBanner:(CDVInvokedUrlCommand *)command {
|
|
317
384
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
385
|
+
[self destroyBannerInternal];
|
|
386
|
+
self.lastAdUnitId = @"";
|
|
387
|
+
self.lastSizeStr = @"";
|
|
388
|
+
CDVPluginResult *pluginResult =
|
|
389
|
+
[CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
|
390
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult
|
|
391
|
+
callbackId:command.callbackId];
|
|
323
392
|
});
|
|
324
393
|
}
|
|
325
394
|
|
|
326
395
|
#pragma mark - Helper Events
|
|
327
396
|
|
|
328
|
-
- (void)sendLoadedEvent:(GADAdSize)adSize
|
|
329
|
-
|
|
330
|
-
|
|
397
|
+
- (void)sendLoadedEvent:(GADAdSize)adSize
|
|
398
|
+
isCollapsible:(BOOL)isCollapsible
|
|
399
|
+
isRefresh:(BOOL)isRefresh {
|
|
400
|
+
NSString *jsonStr = [NSString
|
|
401
|
+
stringWithFormat:@"{\"width\":%f, \"height\":%f, \"isCollapsible\":%s}",
|
|
402
|
+
adSize.size.width, adSize.size.height,
|
|
403
|
+
isCollapsible ? "true" : "false"];
|
|
331
404
|
|
|
332
405
|
if (isRefresh) {
|
|
333
|
-
[self.plugin fireEvent:@"document"
|
|
406
|
+
[self.plugin fireEvent:@"document"
|
|
407
|
+
event:@"on.banner.refreshed"
|
|
408
|
+
withData:nil];
|
|
334
409
|
} else {
|
|
335
|
-
[self.plugin fireEvent:@"document"
|
|
410
|
+
[self.plugin fireEvent:@"document"
|
|
411
|
+
event:@"on.banner.load"
|
|
412
|
+
withData:jsonStr];
|
|
336
413
|
}
|
|
337
414
|
}
|
|
338
415
|
|
|
339
416
|
#pragma mark - GADBannerViewDelegate
|
|
340
417
|
|
|
341
|
-
- (void)bannerViewDidReceiveAd:(GADBannerView *)
|
|
342
|
-
|
|
343
|
-
|
|
418
|
+
- (void)bannerViewDidReceiveAd:(GADBannerView *)incomingBannerView {
|
|
419
|
+
if (incomingBannerView == self.pendingBannerView) {
|
|
420
|
+
self.isLoading = NO;
|
|
344
421
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
self.activeBannerHeight = self.lastAdSize.size.height;
|
|
348
|
-
}
|
|
422
|
+
[self.bannerView removeFromSuperview];
|
|
423
|
+
self.bannerView.delegate = nil;
|
|
349
424
|
|
|
350
|
-
|
|
425
|
+
self.bannerView = self.pendingBannerView;
|
|
426
|
+
self.pendingBannerView = nil;
|
|
427
|
+
|
|
428
|
+
self.activeBannerHeight = incomingBannerView.adSize.size.height;
|
|
429
|
+
if (self.activeBannerHeight == 0) {
|
|
430
|
+
self.activeBannerHeight = self.lastAdSize.size.height;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
[self sendLoadedEvent:self.lastAdSize
|
|
434
|
+
isCollapsible:self.isCollapsible
|
|
435
|
+
isRefresh:NO];
|
|
436
|
+
|
|
437
|
+
if (self.isAutoShow && !self.isBannerVisible) {
|
|
438
|
+
[self showBannerInternal];
|
|
439
|
+
} else {
|
|
440
|
+
[self layoutViews];
|
|
441
|
+
}
|
|
442
|
+
} else if (incomingBannerView == self.bannerView) {
|
|
443
|
+
|
|
444
|
+
[self sendLoadedEvent:incomingBannerView.adSize
|
|
445
|
+
isCollapsible:self.isCollapsible
|
|
446
|
+
isRefresh:YES];
|
|
351
447
|
|
|
352
|
-
if (self.isAutoShow && !self.isBannerVisible) {
|
|
353
|
-
[self showBannerInternal];
|
|
354
|
-
} else {
|
|
355
448
|
[self layoutViews];
|
|
356
449
|
}
|
|
357
450
|
}
|
|
358
451
|
|
|
359
|
-
- (void)bannerView:(GADBannerView *)
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
452
|
+
- (void)bannerView:(GADBannerView *)incomingBannerView
|
|
453
|
+
didFailToReceiveAdWithError:(NSError *)error {
|
|
454
|
+
if (incomingBannerView == self.pendingBannerView) {
|
|
455
|
+
self.isLoading = NO;
|
|
456
|
+
|
|
457
|
+
[incomingBannerView removeFromSuperview];
|
|
458
|
+
incomingBannerView.delegate = nil;
|
|
459
|
+
self.pendingBannerView = nil;
|
|
460
|
+
|
|
461
|
+
NSString *jsonStr = [NSString
|
|
462
|
+
stringWithFormat:@"{\"code\":%ld, \"message\":\"%@\"}",
|
|
463
|
+
(long)error.code, [error localizedDescription]];
|
|
464
|
+
[self.plugin fireEvent:@"document"
|
|
465
|
+
event:@"on.banner.failed"
|
|
466
|
+
withData:jsonStr];
|
|
467
|
+
} else if (incomingBannerView == self.bannerView) {
|
|
468
|
+
|
|
469
|
+
NSString *jsonStr = [NSString
|
|
470
|
+
stringWithFormat:@"{\"code\":%ld, \"message\":\"%@\"}",
|
|
471
|
+
(long)error.code, [error localizedDescription]];
|
|
472
|
+
[self.plugin fireEvent:@"document"
|
|
473
|
+
event:@"on.banner.failedToRefresh"
|
|
474
|
+
withData:jsonStr];
|
|
475
|
+
}
|
|
363
476
|
}
|
|
364
477
|
|
|
365
478
|
- (void)bannerViewDidRecordImpression:(GADBannerView *)bannerView {
|
|
366
|
-
[self.plugin fireEvent:@"document"
|
|
479
|
+
[self.plugin fireEvent:@"document"
|
|
480
|
+
event:@"on.banner.impression"
|
|
481
|
+
withData:nil];
|
|
367
482
|
}
|
|
368
483
|
|
|
369
484
|
- (void)bannerViewDidRecordClick:(GADBannerView *)bannerView {
|
|
@@ -67,6 +67,10 @@
|
|
|
67
67
|
|
|
68
68
|
if ((currentTime - self.lastLoadTime) < self.minLoadInterval) {
|
|
69
69
|
|
|
70
|
+
NSString *errorMsg = [NSString stringWithFormat:@"Request too fast. Please wait %.0fms to prevent invalid traffic.", (self.minLoadInterval * 1000.0)];
|
|
71
|
+
|
|
72
|
+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errorMsg];
|
|
73
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
70
74
|
return;
|
|
71
75
|
}
|
|
72
76
|
|
|
@@ -85,7 +89,6 @@
|
|
|
85
89
|
self.isLoading = NO;
|
|
86
90
|
|
|
87
91
|
if (error) {
|
|
88
|
-
self.interstitialAd = nil;
|
|
89
92
|
|
|
90
93
|
NSString *jsonStr = [NSString stringWithFormat:@"{\"code\":%ld, \"message\":\"%@\"}", (long)error.code, [error localizedDescription]];
|
|
91
94
|
[self.plugin fireEvent:@"document" event:@"on.interstitial.failed.load" withData:jsonStr];
|
|
@@ -69,6 +69,10 @@
|
|
|
69
69
|
|
|
70
70
|
if ((currentTime - self.lastLoadTime) < self.minLoadInterval) {
|
|
71
71
|
|
|
72
|
+
NSString *errorMsg = [NSString stringWithFormat:@"Request too fast. Please wait %.0fms to prevent invalid traffic.", (self.minLoadInterval * 1000.0)];
|
|
73
|
+
|
|
74
|
+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errorMsg];
|
|
75
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
72
76
|
return;
|
|
73
77
|
}
|
|
74
78
|
|
|
@@ -87,7 +91,6 @@
|
|
|
87
91
|
self.isLoading = NO;
|
|
88
92
|
|
|
89
93
|
if (error) {
|
|
90
|
-
self.rewardedAd = nil;
|
|
91
94
|
|
|
92
95
|
NSString *jsonStr = [NSString stringWithFormat:@"{\"code\":%ld, \"message\":\"%@\"}", (long)error.code, [error localizedDescription]];
|
|
93
96
|
[self.plugin fireEvent:@"document" event:@"on.rewarded.failed.load" withData:jsonStr];
|
|
@@ -77,10 +77,10 @@
|
|
|
77
77
|
|
|
78
78
|
if ((currentTime - self.lastLoadTime) < self.minLoadInterval) {
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
NSString *errorMsg = [NSString stringWithFormat:@"Request too fast. Please wait %.0fms to prevent invalid traffic.", (self.minLoadInterval * 1000.0)];
|
|
81
|
+
|
|
82
|
+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errorMsg];
|
|
83
|
+
[self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -101,7 +101,6 @@
|
|
|
101
101
|
self.isLoading = NO;
|
|
102
102
|
|
|
103
103
|
if (error) {
|
|
104
|
-
self.rewardedInterstitialAd = nil;
|
|
105
104
|
|
|
106
105
|
NSString *jsonStr = [NSString stringWithFormat:@"{\"code\":%ld, \"message\":\"%@\"}", (long)error.code, [error localizedDescription]];
|
|
107
106
|
[self.plugin fireEvent:@"document" event:@"on.rewardedInter.failed.load" withData:jsonStr];
|