cordova-plugin-admob-nextgen 1.0.2 → 1.0.4

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 CHANGED
@@ -58,7 +58,13 @@ Move beyond simple 320x50 banners. The Native Overlay feature allows you to rend
58
58
  We prioritize the safety of your AdMob account and the stability of your app.
59
59
 
60
60
  * **Smart Throttling (`retryInterval`)**: Prevents accidental spamming of ad requests using a global interval validation.
61
- * **Background Thread Loading**: All ad requests are dispatched on background threads (`cordova.getThreadPool()`), ensuring your app's UI never freezes.
61
+
62
+ - If the loadAd or showAd function is called repeatedly accidentally by JavaScript (for example because it is tied to a scroll event or application loop), the system will continuously call loadAd or showAd.
63
+ ### This will cause two fatal problems:
64
+ 1. Banner Ad Flickering: Ads are constantly being destroyed and redrawn.
65
+ 2. Account Ban: Aggressively pulling ads (spamming impressions) is a serious violation of AdMob's Invalid Traffic (IVT) policy.
66
+
67
+ * **Background Thread Loading**: All ad requests are dispatched on background threads, ensuring your app's UI never freezes.
62
68
 
63
69
  ---
64
70
 
@@ -78,9 +84,6 @@ Add this to your `config.xml` to restore the plugin automatically.
78
84
  <plugin name="cordova-plugin-admob-nextgen" spec="latest">
79
85
  <variable name="APP_ID_ANDROID" value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy" />
80
86
  <variable name="APP_ID_IOS" value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy" />
81
-
82
- <variable name="NEXT_GEN_SDK_VERSION" value="0.25.0-beta01" />
83
- <variable name="UMP_VERSION" value="4.0.0" />
84
87
  </plugin>
85
88
 
86
89
 
@@ -89,9 +92,10 @@ Add this to your `config.xml` to restore the plugin automatically.
89
92
 
90
93
  **[⚡ AdMob Next Gen - Starter Templates 🚀 ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen-template)**.
91
94
 
92
-
93
95
  ---
94
96
 
97
+ **[⚡ FULL Cordova - simple example 🚀 ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen/tree/main/simple-example/www/js)**.
98
+
95
99
  ## 2. Configuration & Initialization (CRITICAL)
96
100
 
97
101
  **IMPORTANT:** Configure Global Settings and handle Privacy Consent (UMP) **BEFORE** initializing the SDK.
@@ -240,7 +244,7 @@ Supports **Adaptive**, **Standard**, and **Collapsible** banners.
240
244
 
241
245
  ---
242
246
 
243
- ## 4. Native Ads (Advanced Overlay)
247
+ ## 4. Native Ads (Advanced Overlay) - Android Only
244
248
 
245
249
  High-performance native templates.
246
250
 
@@ -283,7 +287,7 @@ High-performance native templates.
283
287
 
284
288
  ---
285
289
 
286
- ## 5. Ad Preloading (Banner)
290
+ ## 5. Ad Preloading (Banner) - Android Only
287
291
 
288
292
  Use the background engine to pool ads for 0ms latency.
289
293
 
@@ -294,8 +298,9 @@ Use the background engine to pool ads for 0ms latency.
294
298
  adUnitId: 'ca-app-pub-xxx/xxx',
295
299
  size: 'ADAPTIVE', // 'BANNER', 'LARGE_BANNER', 'MEDIUM_RECTANGLE', 'ADAPTIVE', 'FULL_BANNER', 'LEADERBOARD'
296
300
  position: 'bottom', // 'top' or 'bottom'
297
- collapsible: false,
298
- isOverlapping: false // Coba mode Push
301
+ collapsible: false, // true = Enable Collapsible Format (High Revenue)
302
+ isOverlapping: false,
303
+ retryInterval: 5000 // Anti-spam delay (ms)
299
304
  });
300
305
 
301
306
  // 2. Show Instantly (from pool)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-admob-nextgen",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Google Mobile Ads Next Gen SDK for Cordova. High performance and modular architecture. ",
5
5
  "cordova": {
6
6
  "id": "cordova-plugin-admob-nextgen",
package/plugin.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <?xml version='1.0' encoding='utf-8'?>
2
2
  <plugin id="cordova-plugin-admob-nextgen"
3
- version="1.0.2"
3
+ version="1.0.4"
4
4
  xmlns="http://apache.org/cordova/ns/plugins/1.0"
5
5
  xmlns:android="http://schemas.android.com/apk/res/android">
6
6
 
@@ -139,6 +139,8 @@
139
139
  <source-file src="src/ios/AdMobNextGen.m" />
140
140
  <header-file src="src/ios/ConsentExecutor.h" />
141
141
  <source-file src="src/ios/ConsentExecutor.m" />
142
+ <header-file src="src/ios/GlobalSettingsExecutor.h" />
143
+ <source-file src="src/ios/GlobalSettingsExecutor.m" />
142
144
  <header-file src="src/ios/AppOpenAdExecutor.h" />
143
145
  <source-file src="src/ios/AppOpenAdExecutor.m" />
144
146
  <header-file src="src/ios/BannerExecutor.h" />
@@ -21,15 +21,17 @@ import com.google.android.libraries.ads.mobile.sdk.banner.AdSize;
21
21
  import com.google.android.libraries.ads.mobile.sdk.banner.BannerAd;
22
22
  import com.google.android.libraries.ads.mobile.sdk.banner.BannerAdEventCallback;
23
23
  import com.google.android.libraries.ads.mobile.sdk.banner.BannerAdPreloader;
24
- import com.google.android.libraries.ads.mobile.sdk.banner.BannerAdRefreshCallback;
24
+ import com.google.android.libraries.ads.mobile.sdk.banner.BannerAdRefreshCallback;
25
25
  import com.google.android.libraries.ads.mobile.sdk.banner.BannerAdRequest;
26
26
  import com.google.android.libraries.ads.mobile.sdk.common.AdValue;
27
- import com.google.android.libraries.ads.mobile.sdk.common.FullScreenContentError;
27
+ import com.google.android.libraries.ads.mobile.sdk.common.FullScreenContentError;
28
28
  import com.google.android.libraries.ads.mobile.sdk.common.LoadAdError;
29
29
  import com.google.android.libraries.ads.mobile.sdk.common.PreloadCallback;
30
30
  import com.google.android.libraries.ads.mobile.sdk.common.PreloadConfiguration;
31
31
  import com.google.android.libraries.ads.mobile.sdk.common.ResponseInfo;
32
32
 
33
+ import java.util.Date;
34
+
33
35
  public class BannerPreloadExecutor {
34
36
 
35
37
  private static final String TAG = "AdMobBannerPreload";
@@ -44,6 +46,14 @@ public class BannerPreloadExecutor {
44
46
 
45
47
  private String currentPosition = "bottom";
46
48
  private boolean isOverlapping = true;
49
+ private boolean isBannerVisible = false;
50
+
51
+ private int lastAdHeight = 0;
52
+ private int systemSafeTop = 0;
53
+ private int systemSafeBottom = 0;
54
+
55
+ private long lastShowTime = 0;
56
+ private long minShowInterval = 5000;
47
57
 
48
58
  public BannerPreloadExecutor(CordovaInterface cordova, CordovaWebView webView) {
49
59
  this.cordova = cordova;
@@ -63,23 +73,27 @@ public class BannerPreloadExecutor {
63
73
  isPreloaderActive = true;
64
74
  this.currentAdUnitId = adUnitId;
65
75
 
76
+ if (options.has("position")) this.currentPosition = options.getString("position");
77
+ if (options.has("isOverlapping")) this.isOverlapping = options.getBoolean("isOverlapping");
78
+
79
+ if (options.has("retryInterval")) this.minShowInterval = options.getLong("retryInterval");
80
+
66
81
  String requestedSize = "ADAPTIVE";
67
82
  if (options.has("size")) requestedSize = options.getString("size");
68
83
 
69
84
  boolean isCollapsible = false;
70
85
  if (options.has("collapsible")) isCollapsible = options.getBoolean("collapsible");
71
86
 
72
- String preloadPosition = "bottom";
73
- if (options.has("position")) preloadPosition = options.getString("position");
74
-
75
87
  final String finalSizeStr = requestedSize;
76
88
  final boolean finalIsCollapsible = isCollapsible;
77
- final String finalPosition = preloadPosition;
89
+ final String finalPosition = this.currentPosition;
78
90
 
79
91
  cordova.getActivity().runOnUiThread(() -> {
80
92
  Context context = cordova.getActivity();
81
93
  AdSize adSize = getAdSize(context, finalSizeStr);
82
94
 
95
+ this.lastAdHeight = adSize.getHeightInPixels(context);
96
+
83
97
  BannerAdRequest.Builder requestBuilder = new BannerAdRequest.Builder(adUnitId, adSize);
84
98
 
85
99
  if (finalIsCollapsible) {
@@ -87,7 +101,6 @@ public class BannerPreloadExecutor {
87
101
  String anchor = "top".equalsIgnoreCase(finalPosition) ? "top" : "bottom";
88
102
  extras.putString("collapsible", anchor);
89
103
  requestBuilder.setGoogleExtrasBundle(extras);
90
-
91
104
  }
92
105
 
93
106
  BannerAdRequest adRequest = requestBuilder.build();
@@ -96,12 +109,10 @@ public class BannerPreloadExecutor {
96
109
  PreloadCallback preloadCallback = new PreloadCallback() {
97
110
  @Override
98
111
  public void onAdPreloaded(@NonNull String preloadId, @NonNull ResponseInfo responseInfo) {
99
-
100
112
  fireEvent("on.preload.available", null);
101
113
  }
102
114
  @Override
103
115
  public void onAdFailedToPreload(@NonNull String preloadId, @NonNull LoadAdError loadAdError) {
104
-
105
116
  try {
106
117
  JSONObject err = new JSONObject();
107
118
  err.put("message", loadAdError.getMessage());
@@ -110,13 +121,11 @@ public class BannerPreloadExecutor {
110
121
  }
111
122
  @Override
112
123
  public void onAdsExhausted(@NonNull String preloadId) {
113
-
114
124
  fireEvent("on.preload.exhausted", null);
115
125
  }
116
126
  };
117
127
 
118
128
  BannerAdPreloader.start(adUnitId, preloadConfig, preloadCallback);
119
-
120
129
  callbackContext.success("Preloader Started");
121
130
  });
122
131
 
@@ -127,51 +136,235 @@ public class BannerPreloadExecutor {
127
136
  }
128
137
 
129
138
  public void showPolledAd(JSONArray args, CallbackContext callbackContext) {
130
- try {
131
- JSONObject options = args.getJSONObject(0);
132
- String adUnitId = options.getString("adUnitId");
139
+ if (currentAdUnitId == null || currentAdUnitId.isEmpty()) {
140
+ callbackContext.error("Preloader engine is not running.");
141
+ return;
142
+ }
133
143
 
134
- if (options.has("position")) this.currentPosition = options.getString("position");
135
- if (options.has("isOverlapping")) this.isOverlapping = options.getBoolean("isOverlapping");
144
+ String newPosition = this.currentPosition;
145
+ boolean newIsOverlapping = this.isOverlapping;
136
146
 
137
- cordova.getActivity().runOnUiThread(() -> {
138
- BannerAd ad = BannerAdPreloader.pollAd(adUnitId);
147
+ if (args != null && args.length() > 0) {
148
+ try {
149
+ JSONObject options = args.getJSONObject(0);
150
+ if (options.has("position")) newPosition = options.getString("position");
151
+ if (options.has("isOverlapping")) newIsOverlapping = options.getBoolean("isOverlapping");
152
+ } catch (JSONException ignored) {}
153
+ }
139
154
 
140
- if (ad == null) {
155
+ if (currentBannerAd != null && isBannerVisible) {
156
+ boolean isSamePos = newPosition.equalsIgnoreCase(this.currentPosition);
157
+ boolean isSameOverlap = (newIsOverlapping == this.isOverlapping);
141
158
 
142
- callbackContext.error("Pool Empty");
143
- return;
144
- }
159
+ if (isSamePos && isSameOverlap) {
145
160
 
146
- destroyCurrentBanner();
147
- this.currentBannerAd = ad;
161
+ callbackContext.success("Banner Already Visible (Flicker Prevented)");
162
+ return;
163
+ } else {
148
164
 
149
- setupAdEvents(ad);
165
+ this.currentPosition = newPosition;
166
+ this.isOverlapping = newIsOverlapping;
150
167
 
151
- renderBannerView(ad);
168
+ cordova.getActivity().runOnUiThread(() -> {
169
+ updateBannerLayout();
170
+ updateWebViewMargins();
171
+ callbackContext.success("Banner Repositioned (No Pool Exhaustion)");
172
+ });
173
+ return;
174
+ }
175
+ }
152
176
 
153
- sendLoadedEvent(ad.getAdSize(), ad.isCollapsible());
177
+ long currentTime = new Date().getTime();
178
+ if ((currentTime - lastShowTime) < minShowInterval) {
179
+ callbackContext.error("Spam protection active: Please wait " + minShowInterval + "ms.");
180
+ return;
181
+ }
182
+
183
+ this.currentPosition = newPosition;
184
+ this.isOverlapping = newIsOverlapping;
185
+ this.lastShowTime = currentTime;
186
+
187
+ cordova.getActivity().runOnUiThread(() -> {
188
+ BannerAd ad = BannerAdPreloader.pollAd(currentAdUnitId);
189
+
190
+ if (ad == null) {
191
+ callbackContext.error("Pool Empty");
192
+ return;
193
+ }
194
+
195
+ destroyCurrentBanner();
196
+ this.currentBannerAd = ad;
197
+
198
+ this.lastAdHeight = ad.getAdSize().getHeightInPixels(cordova.getActivity());
199
+
200
+ setupAdEvents(ad);
201
+ showBannerView();
202
+ sendLoadedEvent(ad.getAdSize(), ad.isCollapsible());
203
+
204
+ callbackContext.success("Ad Shown from Pool");
205
+ });
206
+ }
207
+
208
+ private void showBannerView() {
209
+ if (currentBannerAd == null) return;
210
+
211
+ if (adLayout == null) {
212
+ adLayout = new RelativeLayout(cordova.getActivity());
213
+
214
+ RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
215
+ RelativeLayout.LayoutParams.MATCH_PARENT,
216
+ RelativeLayout.LayoutParams.WRAP_CONTENT);
154
217
 
155
- callbackContext.success("Ad Shown from Pool");
218
+ if ("top".equalsIgnoreCase(currentPosition)) {
219
+ params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
220
+ } else {
221
+ params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
222
+ }
223
+
224
+ adLayout.setClickable(false);
225
+ adLayout.setFocusable(false);
226
+ cordova.getActivity().addContentView(adLayout, params);
227
+ }
228
+
229
+ isBannerVisible = true;
230
+ updateBannerLayout();
231
+
232
+ adLayout.bringToFront();
233
+ adLayout.setVisibility(View.VISIBLE);
234
+
235
+ View adView = currentBannerAd.getView(cordova.getActivity());
236
+ if (adView != null) adView.setVisibility(View.VISIBLE);
237
+
238
+ updateWebViewMargins();
239
+ }
240
+
241
+ private void updateBannerLayout() {
242
+ if (currentBannerAd == null || adLayout == null) return;
243
+
244
+ View adView = currentBannerAd.getView(cordova.getActivity());
245
+ if (adView == null) return;
246
+
247
+ if (adView.getParent() != null && adView.getParent() != adLayout) {
248
+ ((ViewGroup) adView.getParent()).removeView(adView);
249
+ }
250
+
251
+ RelativeLayout.LayoutParams bannerParams = new RelativeLayout.LayoutParams(
252
+ RelativeLayout.LayoutParams.WRAP_CONTENT,
253
+ RelativeLayout.LayoutParams.WRAP_CONTENT);
254
+
255
+ bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
256
+ if ("top".equalsIgnoreCase(currentPosition)) {
257
+ bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
258
+ } else {
259
+ bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
260
+ }
261
+
262
+ if (adView.getParent() == null) {
263
+ adLayout.addView(adView, bannerParams);
264
+ } else {
265
+ adView.setLayoutParams(bannerParams);
266
+ }
267
+
268
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
269
+ adLayout.setOnApplyWindowInsetsListener((v, insets) -> {
270
+
271
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
272
+ systemSafeTop = insets.getInsets(android.view.WindowInsets.Type.systemBars()).top;
273
+ systemSafeBottom = insets.getInsets(android.view.WindowInsets.Type.systemBars()).bottom;
274
+ } else {
275
+ systemSafeTop = insets.getSystemWindowInsetTop();
276
+ systemSafeBottom = insets.getSystemWindowInsetBottom();
277
+ }
278
+
279
+ if (adView != null && adView.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
280
+ RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) adView.getLayoutParams();
281
+ if ("top".equalsIgnoreCase(currentPosition)) {
282
+ params.topMargin = systemSafeTop;
283
+ params.bottomMargin = 0;
284
+ } else {
285
+ params.bottomMargin = systemSafeBottom;
286
+ params.topMargin = 0;
287
+ }
288
+ adView.setLayoutParams(params);
289
+ }
290
+
291
+ updateWebViewMargins();
292
+
293
+ return insets;
156
294
  });
295
+ adLayout.requestApplyInsets();
296
+ }
297
+ }
157
298
 
158
- } catch (JSONException e) {
159
- callbackContext.error(e.getMessage());
299
+ private void updateWebViewMargins() {
300
+ if (webView == null || webView.getView() == null) return;
301
+
302
+ View webViewView = webView.getView();
303
+ ViewGroup.LayoutParams lp = webViewView.getLayoutParams();
304
+
305
+ if (lp instanceof ViewGroup.MarginLayoutParams) {
306
+ ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) lp;
307
+
308
+ if ("top".equalsIgnoreCase(currentPosition)) {
309
+
310
+ params.setMargins(0, 0, 0, 0);
311
+
312
+ if (isBannerVisible && !isOverlapping) {
313
+ float shift = (float) (lastAdHeight + systemSafeTop);
314
+ webViewView.setTranslationY(shift);
315
+ } else {
316
+ webViewView.setTranslationY(0);
317
+ }
318
+ } else {
319
+
320
+ webViewView.setTranslationY(0);
321
+
322
+ if (!isBannerVisible || isOverlapping) {
323
+ params.setMargins(0, 0, 0, 0);
324
+ } else {
325
+ int finalBottom = lastAdHeight + systemSafeBottom;
326
+ params.setMargins(0, 0, 0, finalBottom);
327
+ }
328
+ }
329
+
330
+ webViewView.setLayoutParams(params);
331
+ webViewView.requestLayout();
160
332
  }
161
333
  }
162
334
 
163
- private void setupAdEvents(BannerAd ad) {
335
+ private void destroyCurrentBanner() {
336
+ if (currentBannerAd != null) {
337
+ isBannerVisible = false;
338
+ updateWebViewMargins();
339
+
340
+ View adView = currentBannerAd.getView(cordova.getActivity());
341
+ if (adView != null && adView.getParent() != null) {
342
+ ((ViewGroup) adView.getParent()).removeView(adView);
343
+ }
344
+ currentBannerAd.destroy();
345
+ currentBannerAd = null;
346
+ }
347
+ }
348
+
349
+ public void stopPreloadAndClear() {
350
+ cordova.getActivity().runOnUiThread(() -> {
351
+ isPreloaderActive = false;
352
+ destroyCurrentBanner();
353
+ if (adLayout != null) {
354
+ adLayout.removeAllViews();
355
+ ((ViewGroup)adLayout.getParent()).removeView(adLayout);
356
+ adLayout = null;
357
+ }
358
+ });
359
+ }
164
360
 
361
+ private void setupAdEvents(BannerAd ad) {
165
362
  ad.setAdEventCallback(new BannerAdEventCallback() {
166
363
  @Override
167
- public void onAdImpression() {
168
- fireEvent("on.banner.impression", null);
169
- }
364
+ public void onAdImpression() { fireEvent("on.banner.impression", null); }
170
365
 
171
366
  @Override
172
- public void onAdClicked() {
173
- fireEvent("on.banner.clicked", null);
174
- }
367
+ public void onAdClicked() { fireEvent("on.banner.clicked", null); }
175
368
 
176
369
  @Override
177
370
  public void onAdPaid(@NonNull AdValue adValue) {
@@ -186,20 +379,13 @@ public class BannerPreloadExecutor {
186
379
  }
187
380
 
188
381
  @Override
189
- public void onAdShowedFullScreenContent() {
190
-
191
- fireEvent("on.banner.opened", null);
192
- }
382
+ public void onAdShowedFullScreenContent() { fireEvent("on.banner.opened", null); }
193
383
 
194
384
  @Override
195
- public void onAdDismissedFullScreenContent() {
196
-
197
- fireEvent("on.banner.closed", null);
198
- }
385
+ public void onAdDismissedFullScreenContent() { fireEvent("on.banner.closed", null); }
199
386
 
200
387
  @Override
201
388
  public void onAdFailedToShowFullScreenContent(@NonNull FullScreenContentError error) {
202
-
203
389
  try {
204
390
  JSONObject errData = new JSONObject();
205
391
  errData.put("message", error.getMessage());
@@ -210,14 +396,10 @@ public class BannerPreloadExecutor {
210
396
 
211
397
  ad.setBannerAdRefreshCallback(new BannerAdRefreshCallback() {
212
398
  @Override
213
- public void onAdRefreshed() {
214
-
215
- fireEvent("on.banner.refreshed", null);
216
- }
399
+ public void onAdRefreshed() { fireEvent("on.banner.refreshed", null); }
217
400
 
218
401
  @Override
219
402
  public void onAdFailedToRefresh(@NonNull LoadAdError loadAdError) {
220
-
221
403
  try {
222
404
  JSONObject err = new JSONObject();
223
405
  err.put("message", loadAdError.getMessage());
@@ -231,7 +413,6 @@ public class BannerPreloadExecutor {
231
413
  try {
232
414
  Context context = cordova.getActivity();
233
415
  JSONObject data = new JSONObject();
234
-
235
416
  data.put("width", adSize.getWidth());
236
417
  data.put("height", adSize.getHeight());
237
418
  data.put("widthPixels", adSize.getWidthInPixels(context));
@@ -239,9 +420,7 @@ public class BannerPreloadExecutor {
239
420
  data.put("isCollapsible", isCollapsible);
240
421
 
241
422
  fireEvent("on.banner.load", data);
242
- } catch (JSONException e) {
243
-
244
- }
423
+ } catch (JSONException e) {}
245
424
  }
246
425
 
247
426
  private AdSize getAdSize(Context context, String sizeStr) {
@@ -258,95 +437,6 @@ public class BannerPreloadExecutor {
258
437
  return (int) (displayMetrics.widthPixels / displayMetrics.density);
259
438
  }
260
439
 
261
- private void renderBannerView(BannerAd ad) {
262
- if (adLayout == null) {
263
- adLayout = new RelativeLayout(cordova.getActivity());
264
- RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
265
- RelativeLayout.LayoutParams.MATCH_PARENT,
266
- RelativeLayout.LayoutParams.MATCH_PARENT);
267
- adLayout.setClickable(false);
268
- adLayout.setFocusable(false);
269
- cordova.getActivity().addContentView(adLayout, params);
270
- }
271
-
272
- adLayout.removeAllViews();
273
- adLayout.setVisibility(View.VISIBLE);
274
-
275
- View adView = ad.getView(cordova.getActivity());
276
- RelativeLayout.LayoutParams bannerParams = new RelativeLayout.LayoutParams(
277
- RelativeLayout.LayoutParams.WRAP_CONTENT,
278
- RelativeLayout.LayoutParams.WRAP_CONTENT);
279
-
280
- bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
281
-
282
- if ("top".equalsIgnoreCase(currentPosition)) {
283
- bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
284
- } else {
285
- bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
286
- }
287
-
288
- adLayout.addView(adView, bannerParams);
289
- adLayout.bringToFront();
290
-
291
- updateWebViewMargins(adView);
292
- }
293
-
294
- public void stopPreloadAndClear() {
295
- cordova.getActivity().runOnUiThread(() -> {
296
- isPreloaderActive = false;
297
- destroyCurrentBanner();
298
- if (adLayout != null) {
299
- adLayout.removeAllViews();
300
- ((ViewGroup)adLayout.getParent()).removeView(adLayout);
301
- adLayout = null;
302
- }
303
- });
304
- }
305
-
306
- private void destroyCurrentBanner() {
307
- if (currentBannerAd != null) {
308
- currentBannerAd.destroy();
309
- currentBannerAd = null;
310
- }
311
- resetWebViewMargins();
312
- }
313
-
314
- private void updateWebViewMargins(View adView) {
315
- if (isOverlapping || webView == null || webView.getView() == null) {
316
- resetWebViewMargins();
317
- return;
318
- }
319
-
320
- adView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
321
- int adHeight = adView.getMeasuredHeight();
322
-
323
- View webViewView = webView.getView();
324
- ViewGroup.LayoutParams lp = webViewView.getLayoutParams();
325
-
326
- if (lp instanceof ViewGroup.MarginLayoutParams) {
327
- ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) lp;
328
- if ("top".equalsIgnoreCase(currentPosition)) {
329
- params.setMargins(0, adHeight, 0, 0);
330
- } else {
331
- params.setMargins(0, 0, 0, adHeight);
332
- }
333
- webViewView.setLayoutParams(params);
334
- webViewView.requestLayout();
335
- }
336
- }
337
-
338
- private void resetWebViewMargins() {
339
- if (webView == null || webView.getView() == null) return;
340
- View webViewView = webView.getView();
341
- ViewGroup.LayoutParams lp = webViewView.getLayoutParams();
342
- if (lp instanceof ViewGroup.MarginLayoutParams) {
343
- ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) lp;
344
- params.setMargins(0, 0, 0, 0);
345
- webViewView.setLayoutParams(params);
346
- webViewView.requestLayout();
347
- }
348
- }
349
-
350
440
  private void fireEvent(String eventName, JSONObject data) {
351
441
  cordova.getActivity().runOnUiThread(() -> {
352
442
  StringBuilder js = new StringBuilder();
@@ -12,6 +12,10 @@
12
12
  - (void)requestTrackingAuthorization:(CDVInvokedUrlCommand*)command;
13
13
  - (void)getTrackingAuthorizationStatus:(CDVInvokedUrlCommand*)command;
14
14
 
15
+ - (void)setAppVolume:(CDVInvokedUrlCommand*)command;
16
+ - (void)setAppMuted:(CDVInvokedUrlCommand*)command;
17
+ - (void)setRequestConfiguration:(CDVInvokedUrlCommand*)command;
18
+
15
19
  - (void)createBanner:(CDVInvokedUrlCommand*)command;
16
20
  - (void)showBanner:(CDVInvokedUrlCommand*)command;
17
21
  - (void)hideBanner:(CDVInvokedUrlCommand*)command;
@@ -1,5 +1,6 @@
1
1
  #import "AdMobNextGen.h"
2
2
  #import "ConsentExecutor.h"
3
+ #import "GlobalSettingsExecutor.h"
3
4
  #import "BannerExecutor.h"
4
5
  #import "InterstitialExecutor.h"
5
6
  #import "RewardedExecutor.h"
@@ -8,6 +9,7 @@
8
9
 
9
10
  @interface AdMobNextGen()
10
11
  @property (nonatomic, strong) ConsentExecutor *consentExecutor;
12
+ @property (nonatomic, strong) GlobalSettingsExecutor *globalSettingsExecutor;
11
13
  @property (nonatomic, strong) BannerExecutor *bannerExecutor;
12
14
  @property (nonatomic, strong) InterstitialExecutor *interstitialExecutor;
13
15
  @property (nonatomic, strong) RewardedExecutor *rewardedExecutor;
@@ -19,6 +21,7 @@
19
21
  - (void)pluginInitialize {
20
22
  [super pluginInitialize];
21
23
  self.consentExecutor = [[ConsentExecutor alloc] initWithPlugin:self];
24
+ self.globalSettingsExecutor = [[GlobalSettingsExecutor alloc] initWithPlugin:self];
22
25
  self.bannerExecutor = [[BannerExecutor alloc] initWithPlugin:self];
23
26
  self.interstitialExecutor = [[InterstitialExecutor alloc] initWithPlugin:self];
24
27
  self.rewardedExecutor = [[RewardedExecutor alloc] initWithPlugin:self];
@@ -53,6 +56,10 @@
53
56
  [self.consentExecutor getTCData:command];
54
57
  }
55
58
 
59
+ - (void)canRequestAds:(CDVInvokedUrlCommand *)command {
60
+ [self.consentExecutor canRequestAds:command];
61
+ }
62
+
56
63
  - (void)requestTrackingAuthorization:(CDVInvokedUrlCommand *)command {
57
64
  [self.consentExecutor requestTrackingAuthorization:command];
58
65
  }
@@ -61,17 +68,18 @@
61
68
  [self.consentExecutor getTrackingAuthorizationStatus:command];
62
69
  }
63
70
 
64
- #pragma mark - AppOpenAd Routing
71
+ #pragma mark - Global Settings Routing
65
72
 
66
- - (void)loadAppOpenAd:(CDVInvokedUrlCommand*)command {
67
- NSDictionary *options = [command.arguments objectAtIndex:0];
68
- if (options != nil) {
69
- [[AppOpenAdExecutor sharedInstance] loadAppOpenAd:options command:command];
70
- }
73
+ - (void)setAppVolume:(CDVInvokedUrlCommand*)command {
74
+ [self.globalSettingsExecutor setAppVolume:command];
71
75
  }
72
76
 
73
- - (void)showAppOpenAd:(CDVInvokedUrlCommand*)command {
74
- [[AppOpenAdExecutor sharedInstance] showAppOpenAd:command];
77
+ - (void)setAppMuted:(CDVInvokedUrlCommand*)command {
78
+ [self.globalSettingsExecutor setAppMuted:command];
79
+ }
80
+
81
+ - (void)setRequestConfiguration:(CDVInvokedUrlCommand*)command {
82
+ [self.globalSettingsExecutor setRequestConfiguration:command];
75
83
  }
76
84
 
77
85
  #pragma mark - Banner Routing
@@ -114,8 +122,6 @@
114
122
  [self.interstitialExecutor showInterstitial:command];
115
123
  }
116
124
 
117
- #pragma mark - Rewarded Routing
118
-
119
125
  - (void)createRewarded:(CDVInvokedUrlCommand*)command {
120
126
  NSDictionary *options = [command.arguments objectAtIndex:0];
121
127
  if (options != nil) {
@@ -127,7 +133,16 @@
127
133
  [self.rewardedExecutor showRewarded:command];
128
134
  }
129
135
 
130
- #pragma mark - Rewarded Interstitial Routing
136
+ - (void)loadAppOpenAd:(CDVInvokedUrlCommand*)command {
137
+ NSDictionary *options = [command.arguments objectAtIndex:0];
138
+ if (options != nil) {
139
+ [[AppOpenAdExecutor sharedInstance] loadAppOpenAd:options command:command];
140
+ }
141
+ }
142
+
143
+ - (void)showAppOpenAd:(CDVInvokedUrlCommand*)command {
144
+ [[AppOpenAdExecutor sharedInstance] showAppOpenAd:command];
145
+ }
131
146
 
132
147
  - (void)createRewardedInterstitial:(CDVInvokedUrlCommand*)command {
133
148
  NSDictionary *options = [command.arguments objectAtIndex:0];
@@ -195,9 +195,35 @@
195
195
 
196
196
  CGFloat safeTop = 0;
197
197
  if (@available(iOS 11.0, *)) {
198
- UIWindow *window = UIApplication.sharedApplication.keyWindow;
199
- if (!window) window = superView.window;
200
- safeTop = window.safeAreaInsets.top;
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
+ }
216
+
217
+ if (!window) {
218
+ #pragma clang diagnostic push
219
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
220
+ window = UIApplication.sharedApplication.keyWindow;
221
+ #pragma clang diagnostic pop
222
+ }
223
+
224
+ if (window) {
225
+ safeTop = window.safeAreaInsets.top;
226
+ }
201
227
  }
202
228
 
203
229
  CGRect bannerFrame = CGRectMake(0, 0, superBounds.size.width, self.activeBannerHeight);
@@ -0,0 +1,15 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <Cordova/CDV.h>
3
+ #import <GoogleMobileAds/GoogleMobileAds.h>
4
+
5
+ @class AdMobNextGen;
6
+
7
+ @interface GlobalSettingsExecutor : NSObject
8
+
9
+ - (instancetype)initWithPlugin:(AdMobNextGen *)plugin;
10
+
11
+ - (void)setAppVolume:(CDVInvokedUrlCommand *)command;
12
+ - (void)setAppMuted:(CDVInvokedUrlCommand *)command;
13
+ - (void)setRequestConfiguration:(CDVInvokedUrlCommand *)command;
14
+
15
+ @end
@@ -0,0 +1,136 @@
1
+ #import "GlobalSettingsExecutor.h"
2
+ #import "AdMobNextGen.h"
3
+
4
+ @interface GlobalSettingsExecutor()
5
+ @property (nonatomic, weak) AdMobNextGen *plugin;
6
+ @end
7
+
8
+ @implementation GlobalSettingsExecutor
9
+
10
+ - (instancetype)initWithPlugin:(AdMobNextGen *)plugin {
11
+ self = [super init];
12
+ if (self) {
13
+ self.plugin = plugin;
14
+ }
15
+ return self;
16
+ }
17
+
18
+ - (void)setAppVolume:(CDVInvokedUrlCommand *)command {
19
+ if (command.arguments.count > 0) {
20
+ NSNumber *volumeNum = [command.arguments objectAtIndex:0];
21
+ if ([volumeNum isKindOfClass:[NSNumber class]]) {
22
+ float volume = [volumeNum floatValue];
23
+ GADMobileAds.sharedInstance.applicationVolume = volume;
24
+
25
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
26
+ [self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
27
+ return;
28
+ }
29
+ }
30
+
31
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid volume value"];
32
+ [self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
33
+ }
34
+
35
+ - (void)setAppMuted:(CDVInvokedUrlCommand *)command {
36
+ if (command.arguments.count > 0) {
37
+ NSNumber *mutedNum = [command.arguments objectAtIndex:0];
38
+ if ([mutedNum isKindOfClass:[NSNumber class]]) {
39
+ BOOL muted = [mutedNum boolValue];
40
+ GADMobileAds.sharedInstance.applicationMuted = muted;
41
+
42
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
43
+ [self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
44
+ return;
45
+ }
46
+ }
47
+
48
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid mute value"];
49
+ [self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
50
+ }
51
+
52
+ - (void)setRequestConfiguration:(CDVInvokedUrlCommand *)command {
53
+ if (command.arguments.count == 0) {
54
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Configuration object required"];
55
+ [self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
56
+ return;
57
+ }
58
+
59
+ NSDictionary *config = [command.arguments objectAtIndex:0];
60
+ if (![config isKindOfClass:[NSDictionary class]]) {
61
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid configuration format"];
62
+ [self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
63
+ return;
64
+ }
65
+
66
+ GADRequestConfiguration *requestConfiguration = GADMobileAds.sharedInstance.requestConfiguration;
67
+
68
+ NSNumber *coppaTag = [self parseBooleanFromDict:config key:@"tagForChildDirectedTreatment"];
69
+ if (coppaTag != nil) {
70
+ requestConfiguration.tagForChildDirectedTreatment = coppaTag;
71
+
72
+ }
73
+
74
+ NSNumber *tfuaTag = [self parseBooleanFromDict:config key:@"tagForUnderAgeOfConsent"];
75
+ if (tfuaTag != nil) {
76
+ requestConfiguration.tagForUnderAgeOfConsent = tfuaTag;
77
+
78
+ }
79
+
80
+ if (config[@"maxAdContentRating"] != nil) {
81
+ NSString *rating = config[@"maxAdContentRating"];
82
+ if ([rating isEqualToString:@"G"]) {
83
+ requestConfiguration.maxAdContentRating = GADMaxAdContentRatingGeneral;
84
+ } else if ([rating isEqualToString:@"PG"]) {
85
+ requestConfiguration.maxAdContentRating = GADMaxAdContentRatingParentalGuidance;
86
+ } else if ([rating isEqualToString:@"T"]) {
87
+ requestConfiguration.maxAdContentRating = GADMaxAdContentRatingTeen;
88
+ } else if ([rating isEqualToString:@"MA"]) {
89
+ requestConfiguration.maxAdContentRating = GADMaxAdContentRatingMatureAudience;
90
+ }
91
+
92
+ }
93
+
94
+ if (config[@"testDeviceIds"] != nil && [config[@"testDeviceIds"] isKindOfClass:[NSArray class]]) {
95
+ NSArray *ids = config[@"testDeviceIds"];
96
+ NSMutableArray<NSString *> *testDevices = [NSMutableArray array];
97
+ for (id deviceId in ids) {
98
+ if ([deviceId isKindOfClass:[NSString class]]) {
99
+ [testDevices addObject:deviceId];
100
+ }
101
+ }
102
+ requestConfiguration.testDeviceIdentifiers = testDevices;
103
+
104
+ }
105
+
106
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Configuration Updated"];
107
+ [self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
108
+ }
109
+
110
+ #pragma mark - Helper Parsers
111
+
112
+ - (NSNumber *)parseBooleanFromDict:(NSDictionary *)dict key:(NSString *)key {
113
+ id value = dict[key];
114
+
115
+ if (value == nil || [value isKindOfClass:[NSNull class]]) {
116
+ return nil;
117
+ }
118
+
119
+ if ([value isKindOfClass:[NSNumber class]]) {
120
+ return [value boolValue] ? @YES : @NO;
121
+ }
122
+
123
+ if ([value isKindOfClass:[NSString class]]) {
124
+ NSString *strVal = (NSString *)value;
125
+ if ([[strVal lowercaseString] isEqualToString:@"true"]) {
126
+ return @YES;
127
+ }
128
+ if ([[strVal lowercaseString] isEqualToString:@"false"]) {
129
+ return @NO;
130
+ }
131
+ }
132
+
133
+ return nil;
134
+ }
135
+
136
+ @end
@@ -114,8 +114,8 @@ var AdMobNextGen = {
114
114
  exec(success, error, 'AdMobNextGen', 'startBannerPreload', [options]);
115
115
  },
116
116
 
117
- showPreloadedBanner: function (options, success, error) {
118
- exec(success, error, 'AdMobNextGen', 'showPreloadedBanner', [options]);
117
+ showPreloadedBanner: function (success, error) {
118
+ exec(success, error, 'AdMobNextGen', 'showPreloadedBanner', []);
119
119
  },
120
120
 
121
121
  stopBannerPreload: function (success, error) {