cordova-plugin-admob-nextgen 1.0.2 → 1.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
@@ -78,9 +78,6 @@ Add this to your `config.xml` to restore the plugin automatically.
78
78
  <plugin name="cordova-plugin-admob-nextgen" spec="latest">
79
79
  <variable name="APP_ID_ANDROID" value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy" />
80
80
  <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
81
  </plugin>
85
82
 
86
83
 
@@ -89,9 +86,10 @@ Add this to your `config.xml` to restore the plugin automatically.
89
86
 
90
87
  **[⚡ AdMob Next Gen - Starter Templates 🚀 ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen-template)**.
91
88
 
92
-
93
89
  ---
94
90
 
91
+ **[⚡ FULL Cordova - simple example 🚀 ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen/tree/main/simple-example/www/js)**.
92
+
95
93
  ## 2. Configuration & Initialization (CRITICAL)
96
94
 
97
95
  **IMPORTANT:** Configure Global Settings and handle Privacy Consent (UMP) **BEFORE** initializing the SDK.
@@ -240,7 +238,7 @@ Supports **Adaptive**, **Standard**, and **Collapsible** banners.
240
238
 
241
239
  ---
242
240
 
243
- ## 4. Native Ads (Advanced Overlay)
241
+ ## 4. Native Ads (Advanced Overlay) - Android Only
244
242
 
245
243
  High-performance native templates.
246
244
 
@@ -283,7 +281,7 @@ High-performance native templates.
283
281
 
284
282
  ---
285
283
 
286
- ## 5. Ad Preloading (Banner)
284
+ ## 5. Ad Preloading (Banner) - Android Only
287
285
 
288
286
  Use the background engine to pool ads for 0ms latency.
289
287
 
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.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="1.0.2"
3
+ version="1.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,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" />
@@ -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