cordova-plugin-admob-nextgen 2.0.2 → 2.0.3

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
@@ -117,7 +117,7 @@ This plugin is regularly updated to support the latest standards.
117
117
  | :--- | :--- | :--- | :--- |
118
118
  | **GMA Next-Gen SDK** | Android | **1.4.0** | [View Notes](https://developers.google.com/admob/android/next-gen/rel-notes) |
119
119
  | **UMP SDK** | Android | **4.0.0** | [View Notes](https://developers.google.com/admob/android/privacy/release-notes) |
120
- | **Mobile Ads SDK** | iOS | **13.3.0** | [View Notes](https://developers.google.com/admob/ios/rel-notes) |
120
+ | **Mobile Ads SDK** | iOS | **13.10.0** | [View Notes](https://developers.google.com/admob/ios/rel-notes) |
121
121
  | **UMP SDK** | iOS | **3.1.0** | [View Notes](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/privacy/download) |
122
122
 
123
123
  ### 🎉 View all plugin release notes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-admob-nextgen",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
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="2.0.2"
3
+ version="2.0.3"
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,7 +139,7 @@
139
139
  </config>
140
140
  <pods use-frameworks="true">
141
141
  <pod name="GoogleUserMessagingPlatform" spec="~> 3.1.0" />
142
- <pod name="Google-Mobile-Ads-SDK" spec="~> 13.1.0" />
142
+ <pod name="Google-Mobile-Ads-SDK" spec="~> 13.10.0" />
143
143
  </pods>
144
144
  </podspec>
145
145
 
@@ -52,6 +52,7 @@ public class AdMobNextGen extends CordovaPlugin {
52
52
 
53
53
  private boolean isNativeValidatorDisabled = true;
54
54
  public static boolean isInitialized = false;
55
+ public static boolean isAppInForeground = true;
55
56
 
56
57
  @Override
57
58
  public void pluginInitialize() {
@@ -300,6 +301,7 @@ public class AdMobNextGen extends CordovaPlugin {
300
301
  @Override
301
302
  public void onResume(boolean multitasking) {
302
303
  super.onResume(multitasking);
304
+ isAppInForeground = true;
303
305
  if (appOpenAdExecutor != null && appOpenAdExecutor.shouldAutoShow()) {
304
306
  appOpenAdExecutor.showAdIfAvailable(cordova.getActivity());
305
307
  }
@@ -310,6 +312,12 @@ public class AdMobNextGen extends CordovaPlugin {
310
312
  }
311
313
  }
312
314
 
315
+ @Override
316
+ public void onPause(boolean multitasking) {
317
+ super.onPause(multitasking);
318
+ isAppInForeground = false;
319
+ }
320
+
313
321
  private void initializeSDK(JSONArray args, CallbackContext callbackContext) {
314
322
  String appId = getAppIdFromManifest();
315
323
  if (appId == null) {
@@ -203,10 +203,23 @@ public class AppOpenAdExecutor {
203
203
  }
204
204
  });
205
205
 
206
- isShowingAd = true;
207
206
  cordova.getActivity().runOnUiThread(() -> {
207
+
208
+ if (!AdMobNextGen.isAppInForeground) {
209
+ try {
210
+ JSONObject errData = new JSONObject();
211
+ errData.put("code", "APP_IN_BACKGROUND");
212
+ errData.put("message", "Ad presentation blocked: Application is currently in the background.");
213
+ fireEvent("on.appopen.failed.show", errData);
214
+ } catch (JSONException e) {}
215
+
216
+ return;
217
+ }
218
+
219
+ isShowingAd = true;
208
220
  appOpenAd.show(activity);
209
221
  });
222
+
210
223
  }
211
224
 
212
225
  public boolean shouldAutoShow() {
@@ -84,6 +84,11 @@ public class InterstitialExecutor {
84
84
  requestCallback.success("Ad already loaded and ready");
85
85
  }
86
86
  fireEvent("on.interstitial.loaded", null);
87
+
88
+ if (isAutoShow) {
89
+ showInterstitialAd();
90
+ }
91
+
87
92
  return;
88
93
  }
89
94
 
@@ -115,6 +120,7 @@ public class InterstitialExecutor {
115
120
  if (isAutoShow) {
116
121
  showInterstitialAd();
117
122
  }
123
+
118
124
  }
119
125
 
120
126
  @Override
@@ -152,6 +158,17 @@ public class InterstitialExecutor {
152
158
  Activity activity = cordova.getActivity();
153
159
 
154
160
  activity.runOnUiThread(() -> {
161
+
162
+ if (!AdMobNextGen.isAppInForeground) {
163
+ try {
164
+ JSONObject errData = new JSONObject();
165
+ errData.put("code", "APP_IN_BACKGROUND");
166
+ errData.put("message", "Ad presentation blocked: Application is currently in the background.");
167
+ fireEvent("on.interstitial.failed.show", errData);
168
+ } catch (JSONException e) {}
169
+ return;
170
+ }
171
+
155
172
  interstitialAd.setAdEventCallback(new InterstitialAdEventCallback() {
156
173
 
157
174
  @Override
@@ -84,6 +84,11 @@ public class RewardedExecutor {
84
84
  if (rewardedAd != null) {
85
85
 
86
86
  fireEvent("on.rewarded.loaded", null);
87
+
88
+ if (isAutoShow) {
89
+ showRewardedAd();
90
+ }
91
+
87
92
  return;
88
93
  }
89
94
 
@@ -155,6 +160,16 @@ public class RewardedExecutor {
155
160
 
156
161
  isRewardEarned = false;
157
162
 
163
+ if (!AdMobNextGen.isAppInForeground) {
164
+ try {
165
+ JSONObject errData = new JSONObject();
166
+ errData.put("code", "APP_IN_BACKGROUND");
167
+ errData.put("message", "Ad presentation blocked: Application is currently in the background.");
168
+ fireEvent("on.rewarded.failed.show", errData);
169
+ } catch (JSONException e) {}
170
+ return;
171
+ }
172
+
158
173
  rewardedAd.setAdEventCallback(new RewardedAdEventCallback() {
159
174
 
160
175
  @Override
@@ -73,6 +73,11 @@ public class RewardedInterstitialExecutor {
73
73
  if (callbackContext != null) {
74
74
  callbackContext.success("Ad already loaded");
75
75
  }
76
+
77
+ if (isAutoShow) {
78
+ showRewardedInterstitial(null);
79
+ }
80
+
76
81
  return;
77
82
  }
78
83
 
@@ -138,6 +143,16 @@ public class RewardedInterstitialExecutor {
138
143
 
139
144
  isRewardEarned = false;
140
145
 
146
+ if (!AdMobNextGen.isAppInForeground) {
147
+ try {
148
+ JSONObject errData = new JSONObject();
149
+ errData.put("code", "APP_IN_BACKGROUND");
150
+ errData.put("message", "Ad presentation blocked: Application is currently in the background.");
151
+ fireEvent("on.rewardedInter.failed.show", errData);
152
+ } catch (JSONException e) {}
153
+ return;
154
+ }
155
+
141
156
  mRewardedInterstitialAd.setAdEventCallback(new RewardedInterstitialAdEventCallback() {
142
157
 
143
158
  @Override
@@ -79,6 +79,11 @@
79
79
  CDVPluginResult* res = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Ad Ready"];
80
80
  [self.plugin.commandDelegate sendPluginResult:res callbackId:command.callbackId];
81
81
  }
82
+
83
+ if (self.isAutoShow) {
84
+ [self showAdIfAvailable];
85
+ }
86
+
82
87
  }
83
88
  return;
84
89
  }
@@ -154,6 +159,12 @@
154
159
  return;
155
160
  }
156
161
 
162
+ if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
163
+ NSString *jsonStr = @"{\"code\":\"APP_IN_BACKGROUND\", \"message\":\"Ad presentation blocked: Application is currently in the background or inactive.\"}";
164
+ [self.plugin fireEvent:@"document" event:@"on.appopen.failed.show" withData:jsonStr];
165
+ return;
166
+ }
167
+
157
168
  self.isShowingAd = YES;
158
169
  [self.appOpenAd presentFromRootViewController:self.plugin.viewController];
159
170
  }
@@ -62,6 +62,11 @@
62
62
  if (self.interstitialAd != nil) {
63
63
 
64
64
  [self.plugin fireEvent:@"document" event:@"on.interstitial.loaded" withData:nil];
65
+
66
+ if (self.isAutoShow) {
67
+ [self showInterstitialAd];
68
+ }
69
+
65
70
  return;
66
71
  }
67
72
 
@@ -131,6 +136,12 @@
131
136
  - (void)showInterstitialAd {
132
137
  if (self.interstitialAd == nil) return;
133
138
 
139
+ if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
140
+ NSString *jsonStr = @"{\"code\":\"APP_IN_BACKGROUND\", \"message\":\"Ad presentation blocked: Application is currently in the background.\"}";
141
+ [self.plugin fireEvent:@"document" event:@"on.interstitial.failed.show" withData:jsonStr];
142
+ return;
143
+ }
144
+
134
145
  [self.interstitialAd presentFromRootViewController:self.plugin.viewController];
135
146
  }
136
147
 
@@ -64,6 +64,11 @@
64
64
  if (self.rewardedAd != nil) {
65
65
 
66
66
  [self.plugin fireEvent:@"document" event:@"on.rewarded.loaded" withData:nil];
67
+
68
+ if (self.isAutoShow) {
69
+ [self showRewardedAd];
70
+ }
71
+
67
72
  return;
68
73
  }
69
74
 
@@ -133,6 +138,12 @@
133
138
  - (void)showRewardedAd {
134
139
  if (self.rewardedAd == nil) return;
135
140
 
141
+ if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
142
+ NSString *jsonStr = @"{\"code\":\"APP_IN_BACKGROUND\", \"message\":\"Ad presentation blocked: Application is currently in the background or inactive.\"}";
143
+ [self.plugin fireEvent:@"document" event:@"on.rewarded.failed.show" withData:jsonStr];
144
+ return;
145
+ }
146
+
136
147
  self.isRewardEarned = NO;
137
148
 
138
149
  [self.rewardedAd presentFromRootViewController:self.plugin.viewController
@@ -72,6 +72,12 @@
72
72
  CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Ad Loaded (Cached)"];
73
73
  [self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
74
74
  }
75
+
76
+ if (self.isAutoShow) {
77
+
78
+ [self showRewardedInterstitialAd:nil];
79
+ }
80
+
75
81
  return;
76
82
  }
77
83
 
@@ -144,6 +150,17 @@
144
150
  - (void)showRewardedInterstitialAd:(CDVInvokedUrlCommand *)command {
145
151
  if (self.rewardedInterstitialAd != nil) {
146
152
 
153
+ if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
154
+ NSString *jsonStr = @"{\"code\":\"APP_IN_BACKGROUND\", \"message\":\"Ad presentation blocked: Application is currently in the background or inactive.\"}";
155
+ [self.plugin fireEvent:@"document" event:@"on.rewardedInter.failed.show" withData:jsonStr];
156
+
157
+ if (command) {
158
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Ad presentation blocked: Application is in background."];
159
+ [self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
160
+ }
161
+ return;
162
+ }
163
+
147
164
  self.isRewardEarned = NO;
148
165
 
149
166
  [self.rewardedInterstitialAd presentFromRootViewController:self.plugin.viewController