cordova-plugin-admob-nextgen 1.0.7 → 1.0.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 +16 -7
- package/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/android/AdMobNextGen.java +35 -26
- package/src/ios/BannerExecutor.m +65 -63
package/README.md
CHANGED
|
@@ -86,8 +86,14 @@ Add this to your `config.xml` to restore the plugin automatically.
|
|
|
86
86
|
<variable name="APP_ID_IOS" value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy" />
|
|
87
87
|
</plugin>
|
|
88
88
|
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## (Optional)
|
|
89
92
|
|
|
90
|
-
|
|
93
|
+
### Supporting Mediation: **[⚡ admob-mediation-suite ](https://github.com/swaplab-engine/admob-mediation-suite)** (Optional)
|
|
94
|
+
### Supporting Native ads: **[⚡ cordova-plugin-admob-nextgen-native ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen-native)** (Optional)
|
|
95
|
+
|
|
96
|
+
---
|
|
91
97
|
|
|
92
98
|
## For Capacitor users
|
|
93
99
|
**[⚡ Capacitor Integration: Automated Setup for AdMob Next Gen ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen/discussions/3)**.
|
|
@@ -141,9 +147,10 @@ Add this to your `config.xml` to restore the plugin automatically.
|
|
|
141
147
|
// 3. Initialize the SDK
|
|
142
148
|
function startSdk() {
|
|
143
149
|
admobNextGen.initialize({
|
|
144
|
-
maxAdContentRating: 'G', // 'G'
|
|
145
|
-
tagForChildDirectedTreatment: false,
|
|
146
|
-
tagForUnderAgeOfConsent: false
|
|
150
|
+
maxAdContentRating: 'G', // 'G' | 'PG' | 'T' | 'MA' | ""
|
|
151
|
+
tagForChildDirectedTreatment: false, // true | false | null
|
|
152
|
+
tagForUnderAgeOfConsent: false, // true | false | null
|
|
153
|
+
// isNativeValidatorDisabled: false // optional param for: cordova-plugin-admob-nextgen-native
|
|
147
154
|
}, function() {
|
|
148
155
|
console.log(">>> AdMob SDK Initialized & Ready <<<");
|
|
149
156
|
}, function(err) {
|
|
@@ -247,10 +254,12 @@ Supports **Adaptive**, **Standard**, and **Collapsible** banners.
|
|
|
247
254
|
|
|
248
255
|
## 4. Native Ads (Advanced Overlay) - Android Only
|
|
249
256
|
|
|
257
|
+
- Recommended: **[⚡ cordova-plugin-admob-nextgen-native ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen-native)** (Android | IOS)
|
|
258
|
+
|
|
250
259
|
High-performance native templates.
|
|
251
260
|
|
|
252
261
|
### Example A: Using Templates (Recommended)
|
|
253
|
-
|
|
262
|
+
// Android Only
|
|
254
263
|
admobNextGen.createNativeAd({
|
|
255
264
|
adUnitId: 'ca-app-pub-xxx/xxx',
|
|
256
265
|
view: 'banner_bottom', // Presets: 'banner_top', 'banner_bottom', 'modal_center'
|
|
@@ -259,7 +268,7 @@ High-performance native templates.
|
|
|
259
268
|
});
|
|
260
269
|
|
|
261
270
|
### Example B: Custom Position (Manual Coordinates)
|
|
262
|
-
|
|
271
|
+
// Android Only
|
|
263
272
|
admobNextGen.createNativeAd({
|
|
264
273
|
adUnitId: 'ca-app-pub-xxx/xxx',
|
|
265
274
|
view: 'custom',
|
|
@@ -271,7 +280,7 @@ High-performance native templates.
|
|
|
271
280
|
});
|
|
272
281
|
|
|
273
282
|
### Native Methods & Events
|
|
274
|
-
|
|
283
|
+
// Android Only
|
|
275
284
|
admobNextGen.removeNativeAd();
|
|
276
285
|
|
|
277
286
|
document.addEventListener('on.native.loaded', () => console.log("Native Loaded"));
|
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -40,6 +40,8 @@ public class AdMobNextGen extends CordovaPlugin {
|
|
|
40
40
|
|
|
41
41
|
private BannerPreloadExecutor bannerPreloadExecutor;
|
|
42
42
|
|
|
43
|
+
private boolean isNativeValidatorDisabled = true;
|
|
44
|
+
|
|
43
45
|
@Override
|
|
44
46
|
public void pluginInitialize() {
|
|
45
47
|
super.pluginInitialize();
|
|
@@ -204,38 +206,45 @@ public class AdMobNextGen extends CordovaPlugin {
|
|
|
204
206
|
}
|
|
205
207
|
|
|
206
208
|
private void initializeSDK(JSONArray args, CallbackContext callbackContext) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
cordova.getThreadPool().execute(() -> {
|
|
214
|
-
try {
|
|
215
|
-
InitializationConfig.Builder initConfigBuilder = new InitializationConfig.Builder(appId);
|
|
209
|
+
String appId = getAppIdFromManifest();
|
|
210
|
+
if (appId == null) {
|
|
211
|
+
callbackContext.error("AdMob App ID missing");
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
216
214
|
|
|
217
|
-
|
|
215
|
+
cordova.getThreadPool().execute(() -> {
|
|
216
|
+
try {
|
|
217
|
+
InitializationConfig.Builder initConfigBuilder = new InitializationConfig.Builder(appId);
|
|
218
218
|
|
|
219
|
-
|
|
219
|
+
JSONObject configJson = args.optJSONObject(0);
|
|
220
220
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
221
|
+
if (configJson != null) {
|
|
222
|
+
RequestConfiguration requestConfig = GlobalSettingsExecutor.buildRequestConfiguration(configJson);
|
|
223
|
+
initConfigBuilder.setRequestConfiguration(requestConfig);
|
|
224
224
|
|
|
225
|
-
|
|
225
|
+
this.isNativeValidatorDisabled = configJson.optBoolean("isNativeValidatorDisabled", true);
|
|
226
|
+
} else {
|
|
227
|
+
this.isNativeValidatorDisabled = false;
|
|
228
|
+
}
|
|
226
229
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
config,
|
|
230
|
-
initializationStatus -> {
|
|
231
|
-
cordova.getActivity().runOnUiThread(() -> callbackContext.success("Initialized"));
|
|
232
|
-
}
|
|
233
|
-
);
|
|
234
|
-
} catch (Exception e) {
|
|
235
|
-
cordova.getActivity().runOnUiThread(() -> callbackContext.error(e.getMessage()));
|
|
230
|
+
if (this.isNativeValidatorDisabled) {
|
|
231
|
+
initConfigBuilder.setNativeValidatorDisabled();
|
|
236
232
|
}
|
|
237
|
-
|
|
238
|
-
|
|
233
|
+
|
|
234
|
+
InitializationConfig config = initConfigBuilder.build();
|
|
235
|
+
|
|
236
|
+
MobileAds.initialize(
|
|
237
|
+
cordova.getActivity(),
|
|
238
|
+
config,
|
|
239
|
+
initializationStatus -> {
|
|
240
|
+
cordova.getActivity().runOnUiThread(() -> callbackContext.success("Initialized"));
|
|
241
|
+
}
|
|
242
|
+
);
|
|
243
|
+
} catch (Exception e) {
|
|
244
|
+
cordova.getActivity().runOnUiThread(() -> callbackContext.error(e.getMessage()));
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
239
248
|
|
|
240
249
|
private String getAppIdFromManifest() {
|
|
241
250
|
try {
|
package/src/ios/BannerExecutor.m
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
self.plugin = plugin;
|
|
34
34
|
self.lastAdUnitId = @"";
|
|
35
35
|
self.lastSizeStr = @"";
|
|
36
|
+
|
|
36
37
|
self.currentPosition = @"bottom";
|
|
37
38
|
self.lastPosition = @"bottom";
|
|
38
39
|
|
|
@@ -58,6 +59,29 @@
|
|
|
58
59
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
#pragma mark - Smart Window Helper (Diadopsi dari EmiBanner)
|
|
63
|
+
|
|
64
|
+
- (UIWindow *)getKeyWindow {
|
|
65
|
+
UIWindow *window = nil;
|
|
66
|
+
if (@available(iOS 13.0, *)) {
|
|
67
|
+
for (UIWindowScene *windowScene in [UIApplication sharedApplication].connectedScenes) {
|
|
68
|
+
if (windowScene.activationState == UISceneActivationStateForegroundActive) {
|
|
69
|
+
for (UIWindow *w in windowScene.windows) {
|
|
70
|
+
if (w.isKeyWindow) { window = w; break; }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (window) break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (!window) {
|
|
77
|
+
#pragma clang diagnostic push
|
|
78
|
+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
79
|
+
window = [UIApplication sharedApplication].keyWindow;
|
|
80
|
+
#pragma clang diagnostic pop
|
|
81
|
+
}
|
|
82
|
+
return window;
|
|
83
|
+
}
|
|
84
|
+
|
|
61
85
|
#pragma mark - Main Methods
|
|
62
86
|
|
|
63
87
|
- (void)createBanner:(NSDictionary *)options command:(CDVInvokedUrlCommand *)command {
|
|
@@ -96,7 +120,6 @@
|
|
|
96
120
|
|
|
97
121
|
if (self.bannerView != nil && isSameId && isSameSize) {
|
|
98
122
|
if (self.isAutoShow) {
|
|
99
|
-
|
|
100
123
|
[self showBannerInternal];
|
|
101
124
|
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Banner Updated (Cached)"];
|
|
102
125
|
[self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
@@ -179,84 +202,63 @@
|
|
|
179
202
|
return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.size.width);
|
|
180
203
|
}
|
|
181
204
|
|
|
182
|
-
#pragma mark - NATIVE FRAME MANIPULATION (THE DEFINITIVE WAY)
|
|
183
|
-
|
|
184
205
|
- (void)layoutViews {
|
|
185
206
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
207
|
+
UIViewController *rootVC = self.plugin.viewController;
|
|
186
208
|
UIView *webView = self.plugin.webView;
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (!webView || !superView) return;
|
|
190
|
-
|
|
191
|
-
CGRect superBounds = superView.bounds;
|
|
192
|
-
CGRect webFrame = superBounds;
|
|
193
|
-
|
|
194
|
-
if (self.bannerView && self.activeBannerHeight > 0) {
|
|
195
|
-
|
|
196
|
-
CGFloat safeTop = 0;
|
|
197
|
-
if (@available(iOS 11.0, *)) {
|
|
198
|
-
|
|
199
|
-
UIWindow *window = webView.window;
|
|
200
|
-
|
|
201
|
-
if (!window) {
|
|
202
|
-
if (@available(iOS 13.0, *)) {
|
|
203
|
-
for (UIWindowScene *windowScene in [UIApplication sharedApplication].connectedScenes) {
|
|
204
|
-
if (windowScene.activationState == UISceneActivationStateForegroundActive) {
|
|
205
|
-
for (UIWindow *w in windowScene.windows) {
|
|
206
|
-
if (w.isKeyWindow) {
|
|
207
|
-
window = w;
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (window) break;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
209
|
+
if (!rootVC || !webView) return;
|
|
216
210
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
220
|
-
window = UIApplication.sharedApplication.keyWindow;
|
|
221
|
-
#pragma clang diagnostic pop
|
|
222
|
-
}
|
|
211
|
+
UIWindow *window = [self getKeyWindow];
|
|
212
|
+
UIEdgeInsets safeArea = (window) ? window.safeAreaInsets : UIEdgeInsetsZero;
|
|
223
213
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
}
|
|
214
|
+
CGFloat screenH = UIScreen.mainScreen.bounds.size.height;
|
|
215
|
+
CGFloat screenW = UIScreen.mainScreen.bounds.size.width;
|
|
228
216
|
|
|
229
|
-
|
|
230
|
-
|
|
217
|
+
if (safeArea.bottom == 0 && screenH >= 812.0) safeArea.bottom = 34.0;
|
|
218
|
+
if (safeArea.top == 0 && screenH >= 812.0) safeArea.top = 44.0;
|
|
231
219
|
|
|
232
|
-
|
|
233
|
-
|
|
220
|
+
rootVC.view.backgroundColor = [UIColor blackColor];
|
|
221
|
+
webView.superview.backgroundColor = [UIColor blackColor];
|
|
222
|
+
|
|
223
|
+
CGRect fullScreenRect = CGRectMake(0, 0, screenW, screenH);
|
|
224
|
+
|
|
225
|
+
if (self.isBannerVisible && self.bannerView && self.activeBannerHeight > 0) {
|
|
234
226
|
|
|
235
|
-
|
|
227
|
+
CGSize adSize = self.bannerView.intrinsicContentSize;
|
|
228
|
+
CGFloat bH = adSize.height > 0 ? adSize.height : self.activeBannerHeight;
|
|
229
|
+
CGFloat bW = adSize.width > 0 ? adSize.width : self.bannerView.bounds.size.width;
|
|
230
|
+
CGFloat bX = (screenW - bW) / 2.0;
|
|
231
|
+
CGFloat bY = 0;
|
|
232
|
+
|
|
233
|
+
if ([self.currentPosition isEqualToString:@"top"]) {
|
|
234
|
+
bY = safeArea.top;
|
|
235
|
+
} else {
|
|
236
|
+
bY = screenH - safeArea.bottom - bH;
|
|
236
237
|
}
|
|
237
|
-
self.bannerView.frame = bannerFrame;
|
|
238
238
|
|
|
239
|
-
self.bannerView.
|
|
239
|
+
self.bannerView.frame = CGRectMake(bX, bY, bW, bH);
|
|
240
|
+
self.bannerView.hidden = NO;
|
|
240
241
|
|
|
241
|
-
if (
|
|
242
|
+
if (!self.isOverlapping) {
|
|
243
|
+
CGRect newWebFrame = fullScreenRect;
|
|
242
244
|
if ([self.currentPosition isEqualToString:@"top"]) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
webFrame.size.height = superBounds.size.height - webFrame.origin.y;
|
|
245
|
+
newWebFrame.origin.y = bY + bH;
|
|
246
|
+
newWebFrame.size.height = screenH - newWebFrame.origin.y;
|
|
246
247
|
} else {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
webFrame.size.height = bannerFrame.origin.y;
|
|
248
|
+
newWebFrame.origin.y = 0;
|
|
249
|
+
newWebFrame.size.height = bY;
|
|
250
250
|
}
|
|
251
|
+
webView.frame = newWebFrame;
|
|
252
|
+
} else {
|
|
253
|
+
webView.frame = fullScreenRect;
|
|
251
254
|
}
|
|
252
255
|
} else {
|
|
253
256
|
if (self.bannerView) self.bannerView.hidden = YES;
|
|
257
|
+
webView.frame = fullScreenRect;
|
|
254
258
|
}
|
|
255
259
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (self.bannerView) {
|
|
259
|
-
[superView bringSubviewToFront:self.bannerView];
|
|
260
|
+
if (self.bannerView && self.isBannerVisible) {
|
|
261
|
+
[webView.superview bringSubviewToFront:self.bannerView];
|
|
260
262
|
}
|
|
261
263
|
});
|
|
262
264
|
}
|
|
@@ -266,14 +268,14 @@
|
|
|
266
268
|
- (void)showBannerInternal {
|
|
267
269
|
if (self.bannerView) {
|
|
268
270
|
self.isBannerVisible = YES;
|
|
269
|
-
[self layoutViews];
|
|
271
|
+
[self layoutViews];
|
|
270
272
|
}
|
|
271
273
|
}
|
|
272
274
|
|
|
273
275
|
- (void)hideBannerInternal {
|
|
274
276
|
if (self.bannerView) {
|
|
275
277
|
self.isBannerVisible = NO;
|
|
276
|
-
[self layoutViews];
|
|
278
|
+
[self layoutViews];
|
|
277
279
|
}
|
|
278
280
|
}
|
|
279
281
|
|
|
@@ -282,7 +284,7 @@
|
|
|
282
284
|
self.isBannerVisible = NO;
|
|
283
285
|
self.activeBannerHeight = 0;
|
|
284
286
|
|
|
285
|
-
[self layoutViews];
|
|
287
|
+
[self layoutViews];
|
|
286
288
|
|
|
287
289
|
[self.bannerView removeFromSuperview];
|
|
288
290
|
self.bannerView.delegate = nil;
|