emi-indo-cordova-plugin-admob 1.5.0 → 1.5.2

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.
@@ -1,9 +1,9 @@
1
1
  #import "emiAdmobPlugin.h"
2
- #import <Cordova/CDVPlugin.h>
3
- #import <UserMessagingPlatform/UserMessagingPlatform.h>
4
- #import <AppTrackingTransparency/AppTrackingTransparency.h>
5
2
  #import <AdSupport/AdSupport.h>
3
+ #import <AppTrackingTransparency/AppTrackingTransparency.h>
4
+ #import <Cordova/CDVPlugin.h>
6
5
  #import <Foundation/Foundation.h>
6
+ #import <UserMessagingPlatform/UserMessagingPlatform.h>
7
7
  @implementation emiAdmobPlugin
8
8
  @synthesize appOpenAd;
9
9
  @synthesize bannerView;
@@ -14,510 +14,1772 @@
14
14
  @synthesize responseInfo;
15
15
  @synthesize isPrivacyOptionsRequired;
16
16
  int idfaStatus = 0;
17
- int fromStatus = 0;
17
+ // int fromStatus = 0; // Deprecated
18
+ int Consent_Status = 0;
18
19
  int adFormat = 0;
19
- int adWidth = 320;
20
+ int adWidth = 320; // Default
20
21
  BOOL auto_Show = NO;
21
- NSString *Npa = @"1";
22
- NSString *Position = @"bottom";
23
- BOOL EnableCollapsible = NO;
24
- BOOL ResponseInfo = NO;
22
+ // NSString *Npa = @"1"; // Deprecated
23
+ NSString *Position = @"bottom"; // Default
24
+ NSString *bannerSaveAdUnitId = @""; // autoResize dependency = true
25
+
26
+ BOOL enableCollapsible = NO;
27
+ BOOL isAutoResize = NO;
28
+
25
29
  int isAdSkip = 0;
26
30
  BOOL isIAB = NO;
27
- BOOL UnderAgeOfConsent = NO;- (void)initialize:(CDVInvokedUrlCommand*)command { GADMobileAds *ads = [GADMobileAds sharedInstance];
31
+ BOOL UnderAgeOfConsent = NO;
32
+ BOOL isPrivacyOptions = NO;
33
+ BOOL isDebugGeography = NO;
34
+ BOOL ResponseInfo = NO;
35
+ BOOL isUsingAdManagerRequest = YES;
36
+
37
+ - (BOOL)canRequestAds {
38
+ return UMPConsentInformation.sharedInstance.canRequestAds;
39
+ }
40
+ - (void)setUsingAdManagerRequest:(BOOL)value {
41
+ isUsingAdManagerRequest = value;
42
+ }
43
+ - (void)ResponseInfo:(BOOL)value {
44
+ ResponseInfo = value;
45
+ }
46
+ - (void)isDebugGeography:(BOOL)value {
47
+ isDebugGeography = value;
48
+ }
49
+
50
+ - (void)initialize:(CDVInvokedUrlCommand *)command {
51
+
52
+ NSDictionary *options = [command.arguments objectAtIndex:0];
53
+
54
+ BOOL setAdRequest =
55
+ [[options valueForKey:@"isUsingAdManagerRequest"] boolValue];
56
+ BOOL responseInfo = [[options valueForKey:@"isResponseInfo"] boolValue];
57
+ BOOL setDebugGeography = [[options valueForKey:@"isConsentDebug"] boolValue];
58
+
59
+ [self setUsingAdManagerRequest:setAdRequest];
60
+ [self ResponseInfo:responseInfo];
61
+ [self isDebugGeography:setDebugGeography];
62
+
63
+ __block CDVPluginResult *pluginResult;
64
+ NSString *callbackId = command.callbackId;
65
+ NSString *deviceId = [self __getAdMobDeviceId];
66
+ UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
67
+
68
+ if (isDebugGeography) {
69
+ UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
70
+ parameters.debugSettings = debugSettings;
71
+ debugSettings.geography = UMPDebugGeographyEEA;
72
+ debugSettings.testDeviceIdentifiers = @[ deviceId ];
73
+ }
74
+
75
+ parameters.tagForUnderAgeOfConsent = UnderAgeOfConsent;
76
+
77
+ dispatch_async(dispatch_get_main_queue(), ^{
78
+ // Request consent info update
79
+ [UMPConsentInformation.sharedInstance
80
+ requestConsentInfoUpdateWithParameters:parameters
81
+ completionHandler:^(
82
+ NSError *_Nullable requestConsentError) {
83
+ if (requestConsentError) {
84
+ // NSLog(@"Request consent error: %@",
85
+ // requestConsentError.localizedDescription);
86
+ pluginResult = [CDVPluginResult
87
+ resultWithStatus:CDVCommandStatus_ERROR
88
+ messageAsString:requestConsentError
89
+ .description];
90
+ [self.commandDelegate
91
+ sendPluginResult:pluginResult
92
+ callbackId:callbackId];
93
+ return;
94
+ }
95
+
96
+ // Check the consent status after update
97
+ UMPConsentStatus status =
98
+ UMPConsentInformation.sharedInstance
99
+ .consentStatus;
100
+ // NSLog(@"Consent status: %ld", (long)status);
101
+
102
+ // Handle consent status
103
+ if (status == UMPConsentStatusRequired) {
104
+ // If consent is required, load and display
105
+ // consent form
106
+ [UMPConsentForm loadWithCompletionHandler:^(
107
+ UMPConsentForm *form,
108
+ NSError *loadError) {
109
+ if (loadError) {
110
+ // NSLog(@"Load consent form error: %@",
111
+ // loadError.localizedDescription);
112
+ pluginResult = [CDVPluginResult
113
+ resultWithStatus:CDVCommandStatus_ERROR
114
+ messageAsString:loadError
115
+ .description];
116
+ [self.commandDelegate
117
+ sendPluginResult:pluginResult
118
+ callbackId:callbackId];
119
+ } else {
120
+ // Present the consent form to the user
121
+ [form
122
+ presentFromViewController:
123
+ [UIApplication sharedApplication]
124
+ .delegate.window
125
+ .rootViewController
126
+ completionHandler:^(
127
+ NSError
128
+ *_Nullable dismissError) {
129
+ if (dismissError) {
130
+ // NSLog(@"Dismiss consent
131
+ // form error: %@",
132
+ // dismissError.localizedDescription);
133
+ pluginResult = [CDVPluginResult
134
+ resultWithStatus:
135
+ CDVCommandStatus_ERROR
136
+ messageAsString:
137
+ dismissError
138
+ .description];
139
+ } else {
140
+ // NSLog(@"Consent form
141
+ // successfully
142
+ // presented.");
143
+ pluginResult = [CDVPluginResult
144
+ resultWithStatus:
145
+ CDVCommandStatus_OK
146
+ messageAsString:
147
+ @"Consent form "
148
+ @"displayed "
149
+ @"successfully."];
150
+ }
151
+ [self.commandDelegate
152
+ sendPluginResult:
153
+ pluginResult
154
+ callbackId:
155
+ callbackId];
156
+ }];
157
+ }
158
+
159
+ if (UMPConsentInformation.sharedInstance
160
+ .canRequestAds) {
161
+ [self startGoogleMobileAdsSDK];
162
+ }
163
+ }];
164
+ } else if (status ==
165
+ UMPConsentStatusNotRequired ||
166
+ status == UMPConsentStatusObtained) {
167
+ // If consent is not required or already
168
+ // obtained, start the ads SDK
169
+ if (UMPConsentInformation.sharedInstance
170
+ .canRequestAds) {
171
+ [self startGoogleMobileAdsSDK];
172
+ pluginResult = [CDVPluginResult
173
+ resultWithStatus:CDVCommandStatus_OK
174
+ messageAsString:@"Ads SDK started."];
175
+ } else {
176
+ pluginResult = [CDVPluginResult
177
+ resultWithStatus:CDVCommandStatus_ERROR
178
+ messageAsString:
179
+ @"Cannot request ads, consent is "
180
+ @"required."];
181
+ }
182
+ [self.commandDelegate
183
+ sendPluginResult:pluginResult
184
+ callbackId:callbackId];
185
+ } else {
186
+ // NSLog(@"Consent status unknown or error.");
187
+ pluginResult = [CDVPluginResult
188
+ resultWithStatus:CDVCommandStatus_ERROR
189
+ messageAsString:
190
+ @"Consent status unknown."];
191
+ [self.commandDelegate
192
+ sendPluginResult:pluginResult
193
+ callbackId:callbackId];
194
+ }
195
+ }];
196
+ });
197
+ }
198
+
199
+ - (void)requestIDFA:(CDVInvokedUrlCommand *)command {
200
+ CDVPluginResult *pluginResult;
201
+ NSString *callbackId = command.callbackId;
202
+ if (@available(iOS 14, *)) {
203
+ dispatch_async(dispatch_get_main_queue(), ^{
204
+ [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(
205
+ ATTrackingManagerAuthorizationStatus status) {
206
+ if (status == ATTrackingManagerAuthorizationStatusDenied) {
207
+ idfaStatus = ATTrackingManagerAuthorizationStatusDenied;
208
+ } else if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
209
+ idfaStatus = ATTrackingManagerAuthorizationStatusAuthorized;
210
+ } else if (status == ATTrackingManagerAuthorizationStatusRestricted) {
211
+ idfaStatus = ATTrackingManagerAuthorizationStatusRestricted;
212
+ } else if (status ==
213
+ ATTrackingManagerAuthorizationStatusNotDetermined) {
214
+ idfaStatus = ATTrackingManagerAuthorizationStatusNotDetermined;
215
+ }
216
+ }];
217
+ });
218
+ [self fireEvent:@""
219
+ event:@"on."
220
+ @"getI"
221
+ @"DFA."
222
+ @"stat"
223
+ @"us"
224
+ withData:nil];
225
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
226
+ messageAsInt:idfaStatus];
227
+ } else {
228
+ [self fireEvent:@""
229
+ event:@"on."
230
+ @"getI"
231
+ @"DFA."
232
+ @"erro"
233
+ @"r"
234
+ withData:nil];
235
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
236
+ }
237
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
238
+ }
239
+ /*
240
+ - (void)getConsentRequest:(CDVInvokedUrlCommand *)command {
241
+ }
242
+ */
243
+ - (void)startGoogleMobileAdsSDK {
244
+ static dispatch_once_t onceToken;
245
+ dispatch_once(&onceToken, ^{
246
+ // Initialize the Google Mobile Ads SDK.
247
+ GADMobileAds *ads = [GADMobileAds sharedInstance];
28
248
  [ads startWithCompletionHandler:^(GADInitializationStatus *status) {
29
- // Optional: Log each adapter's initialization latency.
30
- NSDictionary *adapterStatuses = [status adapterStatusesByClassName];
31
- for (NSString *adapter in adapterStatuses) {
32
- GADAdapterStatus *adapterStatus = adapterStatuses[adapter];
33
- NSLog(@"Adapter Name: %@, Description: %@, Latency: %f", adapter,
34
- adapterStatus.description, adapterStatus.latency); } [self fireEvent:@"" event:@"on.sdkInitialization" withData:nil]; }];}- (void)requestIDFA:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult;
35
- NSString *callbackId = command.callbackId; if (@available(iOS 14, *)) {
36
- [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
37
- if (status == ATTrackingManagerAuthorizationStatusDenied) { idfaStatus = ATTrackingManagerAuthorizationStatusDenied;
38
- } else if (status == ATTrackingManagerAuthorizationStatusAuthorized) { idfaStatus = ATTrackingManagerAuthorizationStatusAuthorized;
39
- } else if (status == ATTrackingManagerAuthorizationStatusRestricted) { idfaStatus = ATTrackingManagerAuthorizationStatusRestricted;
40
- } else if (status == ATTrackingManagerAuthorizationStatusNotDetermined) { idfaStatus = ATTrackingManagerAuthorizationStatusNotDetermined;
41
- }
42
- }]; [self fireEvent:@"" event:@"on.getIDFA.status" withData:nil]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:idfaStatus];
43
- } else { [self fireEvent:@"" event:@"on.getIDFA.error" withData:nil];
44
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; } [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
45
- }- (void)getConsentRequest:(CDVInvokedUrlCommand*)command {
46
- CDVPluginResult *pluginResult;
47
- NSString *callbackId = command.callbackId;
48
- UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
49
- // UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
50
- // debugSettings.testDeviceIdentifiers = @[@"59156CDC-B042-4D81-A9FA-900869782912"];
51
- // parameters.debugSettings = debugSettings;
52
- // debugSettings.geography = UMPDebugGeographyEEA;
53
- // BOOL tagForUnderAgeOfConsent = [[command argumentAtIndex:0] boolValue];
54
- parameters.tagForUnderAgeOfConsent = UnderAgeOfConsent; [UMPConsentInformation.sharedInstance
55
- requestConsentInfoUpdateWithParameters:parameters
56
- completionHandler:^(NSError *_Nullable requestConsentError) {
57
- if (requestConsentError) {
58
- // Consent gathering failed.
59
- NSLog(@"Error: %@", requestConsentError.localizedDescription);
60
- return;
61
- } [UMPConsentForm loadAndPresentIfRequiredFromViewController:self.viewController
62
- completionHandler:^(NSError *loadAndPresentError) {
63
- if (loadAndPresentError) {
64
- // Consent gathering failed.
65
- NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
66
- return;
67
- } UMPFormStatus formStatus = UMPConsentInformation.sharedInstance.formStatus; if (formStatus == UMPFormStatusUnknown) { fromStatus = 0; } else if (formStatus == UMPFormStatusAvailable) { fromStatus = 1; } else if (formStatus == UMPFormStatusUnavailable) { fromStatus = 2;
68
- } [self fireEvent:@"" event:@"on.get.from.status" withData:nil]; }]; }]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:fromStatus]; [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
69
- }- (void)showPrivacyOptionsForm:(CDVInvokedUrlCommand*)command { UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
70
- // UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
71
- // debugSettings.testDeviceIdentifiers = @[@"59156CDC-B042-4D81-A9FA-900869782912"];
72
- // parameters.debugSettings = debugSettings;
73
- // debugSettings.geography = UMPDebugGeographyEEA;
74
- // BOOL tagForUnderAgeOfConsent = [[command argumentAtIndex:0] boolValue];
75
- parameters.tagForUnderAgeOfConsent = UnderAgeOfConsent;
76
- [UMPConsentInformation.sharedInstance
77
- requestConsentInfoUpdateWithParameters:parameters
78
- completionHandler:^(NSError *_Nullable requestConsentError) {
79
- // ...
80
- [UMPConsentForm loadAndPresentIfRequiredFromViewController:self.viewController
81
- completionHandler:^(NSError *loadAndPresentError) { }]; [self isPrivacyOptionsRequired]; }]; [UMPConsentForm presentPrivacyOptionsFormFromViewController:self.viewController completionHandler:^(NSError * _Nullable formError) {
82
- if (formError) {
83
- // Handle the error.
84
- NSLog(@"Error: %@", formError.localizedDescription);
85
- [self fireEvent:@"" event:@"on.getPrivacyOptionsFrom.error" withData:nil];
86
- }
87
- }];}- (BOOL)isPrivacyOptionsRequired {
88
- return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus ==
89
- UMPPrivacyOptionsRequirementStatusRequired;
90
- }- (void)pluginInitialize { isIAB = YES; NSMutableDictionary* result = [[NSMutableDictionary alloc] init];
91
- NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; NSNumber* CmpSdkID = [prefs valueForKey:@"IABTCF_CmpSdkID"];
92
- NSString *gdprApplies = [prefs stringForKey:@"IABTCF_gdprApplies"];
93
- NSString *PurposeConsents = [prefs stringForKey:@"IABTCF_PurposeConsents"];
94
- NSString *TCString = [prefs stringForKey:@"IABTCF_TCString"];
95
- result[@"IABTCF_CmpSdkID"] = CmpSdkID;
96
- result[@"IABTCF_gdprApplies"] = gdprApplies;
97
- result[@"IABTCF_PurposeConsents"] = PurposeConsents;
98
- result[@"IABTCF_TCString"] = TCString; NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
99
- [prefs synchronize];}- (void)getIabTfc:(CDVInvokedUrlCommand*)command {
100
- CDVPluginResult *pluginResult;
101
- NSString *callbackId = command.callbackId;
102
- if (isIAB == 1) {
103
- NSMutableDictionary* result = [[NSMutableDictionary alloc] init];
104
- NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; NSNumber* CmpSdkID = [prefs valueForKey:@"IABTCF_CmpSdkID"];
105
- NSString *gdprApplies = [prefs stringForKey:@"IABTCF_gdprApplies"];
106
- NSString *PurposeConsents = [prefs stringForKey:@"IABTCF_PurposeConsents"];
107
- NSString *TCString = [prefs stringForKey:@"IABTCF_TCString"]; result[@"IABTCF_CmpSdkID"] = CmpSdkID;
108
- result[@"IABTCF_gdprApplies"] = gdprApplies;
109
- result[@"IABTCF_PurposeConsents"] = PurposeConsents;
110
- result[@"IABTCF_TCString"] = TCString; [[NSUserDefaults standardUserDefaults] synchronize]; NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
111
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
112
- [self fireEvent:@"" event:@"on.getIabTfc" withData:nil]; } else { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
113
- } [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
114
- }- (void)consentReset:(CDVInvokedUrlCommand*)command {
115
- CDVPluginResult *pluginResult;
116
- NSString *callbackId = command.callbackId;
117
- @try {
118
- [[UMPConsentInformation sharedInstance] reset];
119
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
120
- }@catch (NSException *exception) {
121
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:exception.reason];
122
- }
123
- [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
124
- }- (void)setPublisherFirstPartyIDEnabled:(BOOL)enabled{};- (void)globalSettings:(CDVInvokedUrlCommand*)command {
125
- CDVPluginResult *pluginResult;
126
- NSString *callbackId = command.callbackId;
127
- BOOL setAppMuted = [[command argumentAtIndex:0] boolValue];
128
- float setAppVolume = [[command argumentAtIndex:1] floatValue];
129
- BOOL publisherFirstPartyIdEnabled = [[command argumentAtIndex:3] boolValue];
130
- NSString* npa = [command.arguments objectAtIndex:2];
131
- BOOL enableCollapsible = [[command argumentAtIndex:3] boolValue];
132
- BOOL responseInfo = [[command argumentAtIndex:4] boolValue];
133
- @try {
134
- GADMobileAds.sharedInstance.applicationVolume = setAppVolume;
135
- GADMobileAds.sharedInstance.applicationMuted = setAppMuted;
136
- [self setPublisherFirstPartyIDEnabled:publisherFirstPartyIdEnabled];
137
- Npa = npa;
138
- EnableCollapsible = enableCollapsible;
139
- ResponseInfo = responseInfo;
140
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
141
- }@catch (NSException *exception) {
142
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:exception.reason];
143
- }
144
- [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
145
- }- (void)targeting:(CDVInvokedUrlCommand*)command {
146
- CDVPluginResult *pluginResult;
147
- NSString *callbackId = command.callbackId;
148
- NSNumber *childDirectedTreatment = [command argumentAtIndex:0];
149
- NSNumber *underAgeOfConsent = [command argumentAtIndex:1];
150
- NSString *contentRating = [command argumentAtIndex:2];
151
- @try {
152
- GADRequestConfiguration *requestConfiguration = GADMobileAds.sharedInstance.requestConfiguration;
153
- requestConfiguration.tagForChildDirectedTreatment = childDirectedTreatment;
154
- requestConfiguration.tagForUnderAgeOfConsent = underAgeOfConsent;
155
- requestConfiguration.maxAdContentRating = contentRating;
156
- UnderAgeOfConsent = underAgeOfConsent;
157
- }@catch (NSException *exception) {
158
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:exception.reason];
159
- } [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];}- (GADAdSize)__AdSizeFromString:(NSString *)size
160
- {
161
- if ([size isEqualToString:@"ANCHORED"]) {
162
- return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(adWidth);
163
- } else if ([size isEqualToString:@"IN_LINE"]) {
164
- return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(adWidth);
165
- } else if ([size isEqualToString:@"BANNER"]) {
166
- return GADAdSizeBanner;
167
- } else if ([size isEqualToString:@"LARGE_BANNER"]) {
168
- return GADAdSizeLargeBanner;
169
- } else if ([size isEqualToString:@"FULL_BANNER"]) {
170
- return GADAdSizeFullBanner;
171
- } else if ([size isEqualToString:@"LEADERBOARD"]) {
172
- return GADAdSizeLeaderboard;
173
- } else {
174
- return GADAdSizeBanner;
249
+ NSDictionary *adapterStatuses = [status adapterStatusesByClassName];
250
+ NSMutableArray *adaptersArray = [NSMutableArray array];
251
+
252
+ for (NSString *adapter in adapterStatuses) {
253
+ GADAdapterStatus *adapterStatus = adapterStatuses[adapter];
254
+ NSLog(@"Adapter Name: %@, Description: %@, Latency: %f", adapter,
255
+ adapterStatus.description, adapterStatus.latency);
256
+
257
+ NSDictionary *adapterInfo = @{@"name" : adapter};
258
+
259
+ [adaptersArray addObject:adapterInfo];
260
+ }
261
+
262
+ NSString *sdkVersion = GADGetStringFromVersionNumber(
263
+ GADMobileAds.sharedInstance.versionNumber);
264
+ int Consent_Status =
265
+ (int)UMPConsentInformation.sharedInstance.consentStatus;
266
+
267
+ NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
268
+ NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
269
+ NSNumber *CmpSdkID = [prefs valueForKey:@"IABTCF_CmpSdkID"];
270
+ NSString *gdprApplies = [prefs stringForKey:@"IABTCF_gdprApplies"];
271
+ NSString *PurposeConsents =
272
+ [prefs stringForKey:@"IABTCF_PurposeConsents"];
273
+ NSString *TCString = [prefs stringForKey:@"IABTCF_TCString"];
274
+ NSString *additionalConsent = [prefs stringForKey:@"IABTCF_AddtlConsent"];
275
+
276
+ result[@"version"] = sdkVersion;
277
+ result[@"consentStatus"] = @(Consent_Status);
278
+ result[@"adapter"] = adaptersArray;
279
+ result[@"CmpSdkID"] = CmpSdkID;
280
+ result[@"gdprApplies"] = gdprApplies;
281
+ result[@"PurposeConsents"] = PurposeConsents;
282
+ result[@"TCString"] = TCString;
283
+ result[@"additionalConsent"] = additionalConsent;
284
+
285
+ // NSLog(@"Result dictionary: %@", result);consentStatus
286
+
287
+ NSError *error;
288
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:result
289
+ options:0
290
+ error:&error];
291
+
292
+ if (!jsonData) {
293
+ NSLog(@"Error converting result to JSON: %@",
294
+ error.localizedDescription);
295
+ } else {
296
+ NSString *jsonString =
297
+ [[NSString alloc] initWithData:jsonData
298
+ encoding:NSUTF8StringEncoding];
299
+
300
+ // NSLog(@"JSON String: %@", jsonString);
301
+
302
+ [self fireEvent:@"" event:@"on.sdkInitialization" withData:jsonString];
303
+ }
304
+
305
+ [prefs synchronize];
306
+ }];
307
+ });
308
+ }
309
+
310
+ - (void)forceDisplayPrivacyForm:(CDVInvokedUrlCommand *)command {
311
+ NSString *deviceId = [self __getAdMobDeviceId];
312
+ UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
313
+
314
+ if (isDebugGeography) {
315
+ UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
316
+ debugSettings.geography = UMPDebugGeographyEEA;
317
+ debugSettings.testDeviceIdentifiers = @[ deviceId ];
318
+ parameters.debugSettings = debugSettings;
319
+ }
320
+
321
+ parameters.tagForUnderAgeOfConsent = UnderAgeOfConsent;
322
+
323
+ // [UMPConsentInformation.sharedInstance reset];
324
+
325
+ dispatch_async(dispatch_get_main_queue(), ^{
326
+ [UMPConsentInformation.sharedInstance requestConsentInfoUpdateWithParameters:
327
+ parameters
328
+ completionHandler:^(
329
+ NSError
330
+ *_Nullable requestConsentError) {
331
+ if (requestConsentError !=
332
+ nil) {
333
+ // NSLog(@"Errors
334
+ // in
335
+ // updating
336
+ // consent
337
+ // information:
338
+ // %@",
339
+ // requestConsentError);
340
+ CDVPluginResult
341
+ *pluginResult = [CDVPluginResult
342
+ resultWithStatus:
343
+ CDVCommandStatus_ERROR
344
+ messageAsString:
345
+ requestConsentError
346
+ .description];
347
+ [self.commandDelegate
348
+ sendPluginResult:
349
+ pluginResult
350
+ callbackId:
351
+ command
352
+ .callbackId];
353
+ return;
354
+ }
355
+
356
+ // NSLog(@"Successful
357
+ // update of
358
+ // consent
359
+ // info.
360
+ // Continue to
361
+ // load and
362
+ // present
363
+ // consent
364
+ // form.");
365
+
366
+ [UMPConsentForm loadAndPresentIfRequiredFromViewController:
367
+ self.viewController
368
+ completionHandler:
369
+ ^(NSError
370
+ *loadAndPresentError) {
371
+ if (loadAndPresentError !=
372
+ nil) {
373
+ // NSLog(@"Error loading and presenting consent form: %@", loadAndPresentError);
374
+ CDVPluginResult
375
+ *pluginResult = [CDVPluginResult
376
+ resultWithStatus:
377
+ CDVCommandStatus_ERROR
378
+ messageAsString:
379
+ loadAndPresentError
380
+ .description];
381
+ [self.commandDelegate
382
+ sendPluginResult:
383
+ pluginResult
384
+ callbackId:
385
+ command
386
+ .callbackId];
387
+ } else {
388
+ // NSLog(@"Consent form successfully loaded");
389
+ [UMPConsentForm
390
+ presentPrivacyOptionsFormFromViewController:
391
+ self.viewController
392
+ completionHandler:^(
393
+ NSError
394
+ *_Nullable formError) {
395
+ if (formError) {
396
+ // NSLog(@"Error when displaying the form: %@", formError);
397
+ } else {
398
+ // NSLog(@"The privacy options form is successfully displayed.");
399
+ }
400
+ }];
401
+ }
402
+ }];
403
+ }];
404
+ });
405
+ }
406
+
407
+ - (void)showPrivacyOptionsForm:(CDVInvokedUrlCommand *)command {
408
+ NSString *deviceId = [self __getAdMobDeviceId];
409
+ UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
410
+
411
+ if (isDebugGeography) {
412
+ UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
413
+ parameters.debugSettings = debugSettings;
414
+ debugSettings.geography = UMPDebugGeographyEEA;
415
+ debugSettings.testDeviceIdentifiers = @[ deviceId ];
416
+
417
+ // NSLog(@"[showPrivacyOptionsForm] Using EEA debug geography for
418
+ // consent.");
419
+ }
420
+
421
+ parameters.tagForUnderAgeOfConsent = UnderAgeOfConsent;
422
+
423
+ dispatch_async(dispatch_get_main_queue(),
424
+ ^{
425
+ [UMPConsentInformation.sharedInstance requestConsentInfoUpdateWithParameters:
426
+ parameters
427
+ completionHandler:^(
428
+ NSError
429
+ *_Nullable requestConsentError) {
430
+ if (requestConsentError !=
431
+ nil) {
432
+ // NSLog(@"[showPrivacyOptionsForm] Error in updating consent info: %@", requestConsentError);
433
+ CDVPluginResult
434
+ *pluginResult = [CDVPluginResult
435
+ resultWithStatus:
436
+ CDVCommandStatus_ERROR
437
+ messageAsString:
438
+ requestConsentError
439
+ .description];
440
+ [self.commandDelegate
441
+ sendPluginResult:
442
+ pluginResult
443
+ callbackId:
444
+ command
445
+ .callbackId];
446
+ return;
447
+ }
448
+
449
+ // NSLog(@"[showPrivacyOptionsForm] Successful update of consent info. Continue to load and present consent form.");
450
+
451
+ [UMPConsentForm
452
+ loadAndPresentIfRequiredFromViewController:
453
+ self.viewController
454
+ completionHandler:^(
455
+ NSError
456
+ *loadAndPresentError) {
457
+ if (loadAndPresentError) {
458
+ // NSLog(@"[showPrivacyOptionsForm] Error loading and presenting consent form: %@", loadAndPresentError);
459
+ CDVPluginResult
460
+ *pluginResult = [CDVPluginResult
461
+ resultWithStatus:
462
+ CDVCommandStatus_ERROR
463
+ messageAsString:
464
+ loadAndPresentError
465
+ .description];
466
+ [self.commandDelegate
467
+ sendPluginResult:
468
+ pluginResult
469
+ callbackId:
470
+ command
471
+ .callbackId];
472
+ } else {
473
+ /// NSLog(@"[showPrivacyOptionsForm] Consent form successfully displayed.");
474
+ }
475
+ }];
476
+
477
+ if ([self
478
+ isPrivacyOptionsRequired]) {
479
+ // NSLog(@"[isPrivacyOptionsRequired] Privacy options required.");
480
+ [self
481
+ privacyOptionsFormShow:
482
+ command];
483
+ } else {
484
+ // NSLog(@"[isPrivacyOptionsRequired] Privacy option form not required.");
485
+ CDVPluginResult
486
+ *pluginResult = [CDVPluginResult
487
+ resultWithStatus:
488
+ CDVCommandStatus_OK
489
+ messageAsString:
490
+ @"The privacy option form is not required."];
491
+ [self.commandDelegate
492
+ sendPluginResult:
493
+ pluginResult
494
+ callbackId:
495
+ command
496
+ .callbackId];
497
+ }
498
+ }];
499
+ });
500
+ }
501
+
502
+ - (void)privacyOptionsFormShow:(CDVInvokedUrlCommand *)command {
503
+ [self.commandDelegate runInBackground:^{
504
+ dispatch_async(dispatch_get_main_queue(), ^{
505
+ [UMPConsentForm
506
+ presentPrivacyOptionsFormFromViewController:self.viewController
507
+ completionHandler:^(
508
+ NSError *_Nullable formError) {
509
+ if (formError) {
510
+ // NSLog(@"[privacyOptionsFormShow]
511
+ // Error displaying the privacy options
512
+ // form: %@", formError);
513
+ CDVPluginResult *pluginResult =
514
+ [CDVPluginResult
515
+ resultWithStatus:
516
+ CDVCommandStatus_ERROR
517
+ messageAsString:
518
+ formError.description];
519
+ [self.commandDelegate
520
+ sendPluginResult:pluginResult
521
+ callbackId:command
522
+ .callbackId];
523
+ } else {
524
+ // NSLog(@"[privacyOptionsFormShow] The
525
+ // privacy options form is successfully
526
+ // displayed.");
527
+ }
528
+ }];
529
+ });
530
+ }];
531
+ }
532
+
533
+ // Cek apakah opsi privasi diperlukan
534
+ - (BOOL)isPrivacyOptionsRequired {
535
+ UMPPrivacyOptionsRequirementStatus status =
536
+ UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus;
537
+ // NSLog(@"[isPrivacyOptionsRequired] Privacy option status: %ld",
538
+ // (long)status);
539
+ return status == UMPPrivacyOptionsRequirementStatusRequired;
540
+ }
541
+
542
+ - (void)readStatus:(CDVInvokedUrlCommand *)command {
543
+ [self.commandDelegate runInBackground:^{
544
+ Consent_Status = (int)UMPConsentInformation.sharedInstance.consentStatus;
545
+
546
+ if (Consent_Status == UMPConsentStatusUnknown) {
547
+
548
+ Consent_Status = UMPConsentStatusUnknown;
549
+ } else if (Consent_Status == UMPConsentStatusRequired) {
550
+
551
+ Consent_Status = UMPConsentStatusRequired;
552
+ } else if (Consent_Status == UMPConsentStatusNotRequired) {
553
+
554
+ Consent_Status = UMPConsentStatusNotRequired;
555
+ } else if (Consent_Status == UMPConsentStatusObtained) {
556
+
557
+ Consent_Status = UMPConsentStatusObtained;
175
558
  }
176
- }- (void)loadBannerAd:(CDVInvokedUrlCommand*)command {
177
- if(self.bannerView) {
178
- NSLog(@"Admob banner has been initing");
179
- return;
559
+
560
+ /* NSLog(@"The Consent "
561
+ @"Status %i",
562
+ Consent_Status); */
563
+ CDVPluginResult *pluginResult =
564
+ [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
565
+ messageAsInt:Consent_Status];
566
+ [self.commandDelegate sendPluginResult:pluginResult
567
+ callbackId:command.callbackId];
568
+ }];
569
+ }
570
+
571
+ - (void)getIabTfc:(CDVInvokedUrlCommand *)command {
572
+ CDVPluginResult *pluginResult;
573
+ NSString *callbackId = command.callbackId;
574
+ if (isIAB == 1) {
575
+ NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
576
+ NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
577
+ NSNumber *CmpSdkID = [prefs valueForKey:@"IABT"
578
+ @"CF_"
579
+ @"CmpS"
580
+ @"dkI"
581
+ @"D"];
582
+ NSString *gdprApplies = [prefs stringForKey:@"IABT"
583
+ @"CF_"
584
+ @"gdpr"
585
+ @"Appl"
586
+ @"ie"
587
+ @"s"];
588
+ NSString *PurposeConsents = [prefs stringForKey:@"IABT"
589
+ @"CF_"
590
+ @"Purp"
591
+ @"oseC"
592
+ @"onse"
593
+ @"nt"
594
+ @"s"];
595
+ NSString *TCString = [prefs stringForKey:@"IABT"
596
+ @"CF_"
597
+ @"TCSt"
598
+ @"rin"
599
+ @"g"];
600
+ result[@"IABTCF_"
601
+ @"CmpSdkID"] = CmpSdkID;
602
+ result[@"IABTCF_"
603
+ @"gdprAppli"
604
+ @"es"] = gdprApplies;
605
+ result[@"IABTCF_"
606
+ @"PurposeCo"
607
+ @"nsents"] = PurposeConsents;
608
+ result[@"IABTCF_"
609
+ @"TCString"] = TCString;
610
+ [[NSUserDefaults standardUserDefaults] synchronize];
611
+ NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
612
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
613
+ messageAsDictionary:result];
614
+ [self fireEvent:@""
615
+ event:@"on."
616
+ @"getI"
617
+ @"abTf"
618
+ @"c"
619
+ withData:nil];
620
+ } else {
621
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
622
+ }
623
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
624
+ }
625
+ - (void)consentReset:(CDVInvokedUrlCommand *)command {
626
+ CDVPluginResult *pluginResult;
627
+ NSString *callbackId = command.callbackId;
628
+ @try {
629
+ [[UMPConsentInformation sharedInstance] reset];
630
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
631
+ } @catch (NSException *exception) {
632
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
633
+ messageAsString:exception.reason];
634
+ }
635
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
636
+ }
637
+
638
+ - (void)globalSettings:(CDVInvokedUrlCommand *)command {
639
+ CDVPluginResult *pluginResult;
640
+ NSString *callbackId = command.callbackId;
641
+ NSDictionary *options = [command.arguments objectAtIndex:0];
642
+ BOOL setAppMuted = [[options valueForKey:@"setAppMuted"] boolValue];
643
+ BOOL setAppVolume = [[options valueForKey:@"setAppVolume"] boolValue];
644
+ BOOL pubIdEnabled = [[options valueForKey:@"pubIdEnabled"] boolValue];
645
+ @try {
646
+ GADMobileAds.sharedInstance.applicationVolume = setAppVolume;
647
+ GADMobileAds.sharedInstance.applicationMuted = setAppMuted;
648
+ [GADMobileAds.sharedInstance.requestConfiguration
649
+ setPublisherFirstPartyIDEnabled:pubIdEnabled];
650
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
651
+ } @catch (NSException *exception) {
652
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
653
+ messageAsString:exception.reason];
654
+ }
655
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
656
+ }
657
+
658
+ - (void)targeting:(CDVInvokedUrlCommand *)command {
659
+ CDVPluginResult *pluginResult;
660
+ NSString *callbackId = command.callbackId;
661
+ NSDictionary *options = [command.arguments objectAtIndex:0];
662
+ BOOL childDirectedTreatment =
663
+ [[options valueForKey:@"childDirectedTreatment"] boolValue];
664
+ BOOL underAgeOfConsent =
665
+ [[options valueForKey:@"underAgeOfConsent"] boolValue];
666
+ NSString *contentRating = [options valueForKey:@"contentRating"];
667
+ @try {
668
+ GADRequestConfiguration *requestConfiguration =
669
+ GADMobileAds.sharedInstance.requestConfiguration;
670
+ requestConfiguration.tagForChildDirectedTreatment =
671
+ @(childDirectedTreatment);
672
+ requestConfiguration.tagForUnderAgeOfConsent = @(underAgeOfConsent);
673
+
674
+ if (contentRating != nil) {
675
+ if ([contentRating isEqualToString:@"G"]) {
676
+ requestConfiguration.maxAdContentRating = GADMaxAdContentRatingGeneral;
677
+ } else if ([contentRating isEqualToString:@"PG"]) {
678
+ requestConfiguration.maxAdContentRating =
679
+ GADMaxAdContentRatingParentalGuidance;
680
+ } else if ([contentRating isEqualToString:@"T"]) {
681
+ requestConfiguration.maxAdContentRating = GADMaxAdContentRatingTeen;
682
+ } else if ([contentRating isEqualToString:@"MA"]) {
683
+ requestConfiguration.maxAdContentRating =
684
+ GADMaxAdContentRatingMatureAudience;
685
+ } else {
686
+ // NSLog(@"Unknown content rating: %@", contentRating);
687
+ }
180
688
  }
181
- CDVPluginResult *pluginResult;
182
- NSString *callbackId = command.callbackId; adFormat = 3; if (adFormat == 3) { UIView *parentView = [self.webView superview]; NSString* adUnitId = [command.arguments objectAtIndex:0];
183
- // NSNumber* x = [command.arguments objectAtIndex:1];
184
- // NSNumber* y = [command.arguments objectAtIndex:2];
185
- NSString* position = [command.arguments objectAtIndex:1];
186
- NSString* size = [command.arguments objectAtIndex:2]; NSString* collapsible = [command.arguments objectAtIndex:3];
187
- NSNumber* adaptive_Width = [command.arguments objectAtIndex:4];
188
- BOOL autoShow = [[command argumentAtIndex:5] boolValue];
189
- auto_Show = autoShow;
190
- int intValue = [adaptive_Width intValue];
191
- adWidth = intValue;
192
- Position = position;
193
- // float posX = [x floatValue];
194
- // float posY = [y floatValue];
195
- GADAdSize sizes = [self __AdSizeFromString:size]; // CGPoint origin = CGPointMake(posX,posY);
196
- self.bannerView = [[GADBannerView alloc]
197
- initWithAdSize:sizes]; GADRequest *request = [GADRequest request];
198
- GADExtras *extras = [[GADExtras alloc] init];
199
- if (EnableCollapsible){
200
- extras.additionalParameters = @{@"collapsible" : collapsible};
689
+
690
+ UnderAgeOfConsent = underAgeOfConsent;
691
+
692
+ } @catch (NSException *exception) {
693
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
694
+ messageAsString:exception.reason];
695
+ }
696
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
697
+ }
698
+
699
+ - (void)pluginInitialize {
700
+ [super pluginInitialize];
701
+
702
+ [[NSNotificationCenter defaultCenter]
703
+ addObserver:self
704
+ selector:@selector(orientationDidChange:)
705
+ name:UIDeviceOrientationDidChangeNotification
706
+ object:nil];
707
+
708
+ isIAB = YES;
709
+ NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
710
+ NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
711
+ NSNumber *CmpSdkID = [prefs valueForKey:@"IABTCF"
712
+ @"_CmpSd"
713
+ @"kID"];
714
+ NSString *gdprApplies = [prefs stringForKey:@"IABTCF"
715
+ @"_gdprA"
716
+ @"pplie"
717
+ @"s"];
718
+ NSString *PurposeConsents = [prefs stringForKey:@"IABTCF"
719
+ @"_Purpo"
720
+ @"seCons"
721
+ @"ents"];
722
+ NSString *TCString = [prefs stringForKey:@"IABTCF"
723
+ @"_TCStr"
724
+ @"ing"];
725
+ result[@"IABTCF_"
726
+ @"CmpSdkID"] = CmpSdkID;
727
+ result[@"IABTCF_"
728
+ @"gdprApplies"] = gdprApplies;
729
+ result[@"IABTCF_"
730
+ @"PurposeCons"
731
+ @"ents"] = PurposeConsents;
732
+ result[@"IABTCF_"
733
+ @"TCString"] = TCString;
734
+ // NSLog(@"%@",
735
+ // [[NSUserDefaults
736
+ // standardUserDefaults]
737
+ // dictionaryRepresentation]);
738
+ [prefs synchronize];
739
+ }
740
+
741
+ - (void)orientationDidChange:(NSNotification *)notification {
742
+ // NSLog(@"Orientation changed");
743
+ [self fireEvent:@"" event:@"on.screen.rotated" withData:nil];
744
+ if (isAutoResize) {
745
+ dispatch_async(dispatch_get_main_queue(), ^{
746
+ @try {
747
+
748
+ if (self.bannerView) {
749
+ UIView *parentView = self.bannerView.superview;
750
+ if (parentView != nil) {
751
+ [self.bannerView removeFromSuperview];
752
+ }
753
+ }
754
+
755
+ self.bannerViewLayout = [[UIView alloc] initWithFrame:CGRectZero];
756
+ self.bannerViewLayout.translatesAutoresizingMaskIntoConstraints = NO;
757
+
758
+ UIView *rootView = self.viewController.view;
759
+ if ([rootView isKindOfClass:[UIView class]]) {
760
+ [rootView addSubview:self.bannerViewLayout];
761
+
762
+ [self.bannerViewLayout.topAnchor
763
+ constraintEqualToAnchor:rootView.topAnchor]
764
+ .active = YES;
765
+ [self.bannerViewLayout.leadingAnchor
766
+ constraintEqualToAnchor:rootView.leadingAnchor]
767
+ .active = YES;
768
+ [self.bannerViewLayout.trailingAnchor
769
+ constraintEqualToAnchor:rootView.trailingAnchor]
770
+ .active = YES;
771
+ [self.bannerViewLayout.heightAnchor constraintEqualToConstant:50]
772
+ .active = YES;
201
773
  }
202
- extras.additionalParameters = @{@"npa": Npa};
203
- [request registerAdNetworkExtras:extras];
204
- self.bannerView.adUnitID = adUnitId;
205
- self.bannerView.rootViewController = self.viewController;
774
+
775
+ self.bannerView = [[GADBannerView alloc]
776
+ initWithAdSize:
777
+ GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(
778
+ rootView.frame.size.width)];
779
+ self.bannerView.adUnitID = bannerSaveAdUnitId;
206
780
  self.bannerView.delegate = self;
207
- [self.bannerView loadRequest:request];
208
- self.bannerView.hidden = YES;
209
- [parentView addSubview:self.bannerView];
210
- [parentView bringSubviewToFront:self.bannerView]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
211
- } else {
212
- NSLog(@"Admob Option invalid for banner");
213
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
214
- }
215
- [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
216
- }- (void)showBannerAd:(CDVInvokedUrlCommand*)command {
217
- CDVPluginResult *pluginResult;
218
- NSString *callbackId = command.callbackId;
219
- if(self.bannerView) {
220
- self.bannerView.hidden = NO; [self addBannerViewToView:command]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
221
- } else {
222
- [self fireEvent:@"" event:@"on.banner.failed.show" withData:nil];
223
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
224
- }
781
+ [self.bannerView loadRequest:[GADRequest request]];
782
+
783
+ [self.bannerViewLayout addSubview:self.bannerView];
784
+ [self.bannerViewLayout bringSubviewToFront:self.bannerView];
785
+
786
+ } @catch (NSException *exception) {
787
+ // NSLog(@"Error adjusting banner size: %@", exception.reason);
788
+ // PUBLIC_CALLBACKS.error([NSString stringWithFormat:@"Error adjusting
789
+ // banner size: %@", exception.reason]);
790
+ }
791
+ });
792
+ }
793
+ }
794
+
795
+ - (void)addBannerConstraints {
796
+ self.bannerView.translatesAutoresizingMaskIntoConstraints = NO;
797
+
798
+ // Tambahkan constraint berdasarkan posisi
799
+ if ([Position isEqualToString:@"bottom-center"]) {
800
+ [self.viewController.view addConstraints:@[
801
+ [NSLayoutConstraint
802
+ constraintWithItem:self.bannerView
803
+ attribute:NSLayoutAttributeBottom
804
+ relatedBy:NSLayoutRelationEqual
805
+ toItem:self.viewController.view.safeAreaLayoutGuide
806
+ attribute:NSLayoutAttributeBottom
807
+ multiplier:1
808
+ constant:0],
809
+ [NSLayoutConstraint constraintWithItem:self.bannerView
810
+ attribute:NSLayoutAttributeCenterX
811
+ relatedBy:NSLayoutRelationEqual
812
+ toItem:self.viewController.view
813
+ attribute:NSLayoutAttributeCenterX
814
+ multiplier:1
815
+ constant:0]
816
+ ]];
817
+ } else if ([Position isEqualToString:@"top-center"]) {
818
+ [self.viewController.view addConstraints:@[
819
+ [NSLayoutConstraint
820
+ constraintWithItem:self.bannerView
821
+ attribute:NSLayoutAttributeTop
822
+ relatedBy:NSLayoutRelationEqual
823
+ toItem:self.viewController.view.safeAreaLayoutGuide
824
+ attribute:NSLayoutAttributeTop
825
+ multiplier:1
826
+ constant:0],
827
+ [NSLayoutConstraint constraintWithItem:self.bannerView
828
+ attribute:NSLayoutAttributeCenterX
829
+ relatedBy:NSLayoutRelationEqual
830
+ toItem:self.viewController.view
831
+ attribute:NSLayoutAttributeCenterX
832
+ multiplier:1
833
+ constant:0]
834
+ ]];
835
+ }
836
+ }
837
+
838
+ - (void)loadBannerAd:(CDVInvokedUrlCommand *)command {
839
+ CDVPluginResult *pluginResult;
840
+ NSString *callbackId = command.callbackId;
841
+ adFormat = 3;
842
+ NSDictionary *options = [command.arguments objectAtIndex:0];
843
+ NSString *adUnitId = [options valueForKey:@"adUnitId"];
844
+ NSString *position = [options valueForKey:@"position"];
845
+ NSString *collapsible = [options valueForKey:@"collapsible"];
846
+ BOOL autoResize = [[options valueForKey:@"autoResize"] boolValue];
847
+ NSString *size = [options valueForKey:@"size"];
848
+ BOOL autoShow = [[options valueForKey:@"autoShow"] boolValue];
849
+
850
+ bannerSaveAdUnitId = adUnitId;
851
+
852
+ if (adUnitId == nil || [adUnitId length] == 0) {
853
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
854
+ messageAsString:@"Ad unit ID is required"];
225
855
  [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
226
- }- (void)addBannerViewToView:(CDVInvokedUrlCommand*)command{ bannerView.translatesAutoresizingMaskIntoConstraints = NO;
227
- [self.viewController.view addSubview:bannerView];
228
- if ([Position isEqualToString:@"bottom-center"]){
229
- [self.viewController.view addConstraints:@[
230
- [NSLayoutConstraint constraintWithItem:bannerView
231
- attribute:NSLayoutAttributeBottom
232
- relatedBy:NSLayoutRelationEqual
233
- toItem:self.viewController.view.safeAreaLayoutGuide
234
- attribute:NSLayoutAttributeBottom
235
- multiplier:1
236
- constant:0 ],
237
- [NSLayoutConstraint constraintWithItem:bannerView
238
- attribute:NSLayoutAttributeCenterX
239
- relatedBy:NSLayoutRelationEqual
240
- toItem:self.viewController.view
241
- attribute:NSLayoutAttributeCenterX
242
- multiplier:1
243
- constant:0]
244
- ]];
245
- } else {
246
- [self.viewController.view addConstraints:@[
247
- [NSLayoutConstraint constraintWithItem:bannerView
248
- attribute:NSLayoutAttributeTop
249
- relatedBy:NSLayoutRelationEqual
250
- toItem:self.viewController.view.safeAreaLayoutGuide
251
- attribute:NSLayoutAttributeTop
252
- multiplier:1
253
- constant:0],
254
- [NSLayoutConstraint constraintWithItem:bannerView
255
- attribute:NSLayoutAttributeCenterX
256
- relatedBy:NSLayoutRelationEqual
257
- toItem:self.viewController.view
258
- attribute:NSLayoutAttributeCenterX
259
- multiplier:1
260
- constant:0]
261
- ]];
262
- }}- (void)hideBannerAd:(CDVInvokedUrlCommand*)command {
263
- CDVPluginResult *pluginResult;
264
- NSString *callbackId = command.callbackId;
265
- if(self.bannerView) {
266
- self.bannerView.hidden = YES;
267
- [self fireEvent:@"" event:@"on.banner.hide" withData:nil];
268
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
269
- } else {
270
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
271
- }
272
- [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
273
- }- (void)removeBannerAd:(CDVInvokedUrlCommand*)command {
274
- CDVPluginResult *pluginResult;
275
- NSString *callbackId = command.callbackId;
276
- if(self.bannerView) {
277
- self.bannerView.hidden = YES;
278
- [self.bannerView removeFromSuperview];
279
- self.bannerView = nil;
280
- [self fireEvent:@"" event:@"on.banner.remove" withData:nil];
281
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
282
- } else {
283
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
284
- }
285
- [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];}- (void)loadAppOpenAd:(CDVInvokedUrlCommand *)command {
286
- CDVPluginResult *pluginResult;
287
- NSString *callbackId = command.callbackId;
288
- NSString* adUnitId = [command.arguments objectAtIndex:0];
289
- BOOL autoShow = [[command argumentAtIndex:1] boolValue];
290
- auto_Show = autoShow;
291
- adFormat = 1;
292
- self.appOpenAd = nil;
293
- if (adFormat == 1){
294
- GADRequest *request = [GADRequest request];
295
- GADExtras *extras = [[GADExtras alloc] init];
296
- extras.additionalParameters = @{@"npa": Npa};
297
- [request registerAdNetworkExtras:extras];
298
- [GADAppOpenAd loadWithAdUnitID:adUnitId
299
- request:request
300
- orientation:UIInterfaceOrientationPortrait
301
- completionHandler:^(GADAppOpenAd *ad, NSError *error) {
302
- if (error) {
303
- [self fireEvent:@"" event:@"on.appOpenAd.failed.loaded" withData:nil];
304
- NSLog(@"Failed to load App Open Ad ad with error: %@", [error localizedDescription]); return;
305
- }
306
- self.appOpenAd = ad;
307
- self.appOpenAd.fullScreenContentDelegate = self;
308
- [self fireEvent:@"" event:@"on.appOpenAd.loaded" withData:nil];
309
- if (auto_Show){ if (self.appOpenAd && [self.appOpenAd
310
- canPresentFromRootViewController:self.viewController
311
- error:nil]) { [self.appOpenAd presentFromRootViewController:self.viewController]; } else {
312
- [self fireEvent:@"" event:@"on.appOpenAd.failed.show" withData:nil];
313
- }}
314
- }]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
315
- } [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];}- (void)showAppOpenAd:(CDVInvokedUrlCommand *)command {
316
- CDVPluginResult *pluginResult;
317
- NSString *callbackId = command.callbackId;
318
- if (self.appOpenAd && [self.appOpenAd
319
- canPresentFromRootViewController:self.viewController
320
- error:nil]) { [self.appOpenAd presentFromRootViewController:self.viewController]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; } else { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
321
- [self fireEvent:@"" event:@"on.appOpenAd.failed.show" withData:nil];
322
- }
323
- [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
324
- }- (void)loadInterstitialAd:(CDVInvokedUrlCommand *)command {
325
- CDVPluginResult *pluginResult;
326
- NSString *callbackId = command.callbackId;
327
- NSString* adUnitId = [command.arguments objectAtIndex:0];
328
- BOOL autoShow = [[command argumentAtIndex:1] boolValue];
329
- auto_Show = autoShow;
330
- adFormat = 2;
331
- if (adFormat == 2){
332
- GADRequest *request = [GADRequest request];
333
- [GADInterstitialAd
334
- loadWithAdUnitID:adUnitId
335
- request:request
336
- completionHandler:^(GADInterstitialAd *ad, NSError *error) {
337
- if (error) { NSLog(@"Failed to load interstitial ad with error: %@", [error localizedDescription]);
338
- // [self fireEvent:@"" event:@"on.interstitial.failed.load" withData:nil]; return;
339
- } self.interstitial = ad;
340
- self.interstitial.fullScreenContentDelegate = self;
341
- [self fireEvent:@"" event:@"on.interstitial.loaded" withData:nil]; if (auto_Show){ if (self.interstitial && [self.interstitial
342
- canPresentFromRootViewController:self.viewController error:nil]) { [self.interstitial presentFromRootViewController:self.viewController]; } else { [self fireEvent:@"" event:@"on.interstitial.failed.show" withData:nil];
343
- } } }];
344
- } pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
345
- }- (void)showInterstitialAd:(CDVInvokedUrlCommand *)command {
346
- CDVPluginResult *pluginResult;
347
- NSString *callbackId = command.callbackId;
348
- if (self.interstitial && [self.interstitial
349
- canPresentFromRootViewController:self.viewController error:nil]) { [self.interstitial presentFromRootViewController:self.viewController];
350
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
351
- } else {
352
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
353
- [self fireEvent:@"" event:@"on.interstitial.failed.show" withData:nil];
354
- } [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
355
- }- (void)loadRewardedInterstitialAd:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult;
356
- NSString *callbackId = command.callbackId;
357
- NSString* adUnitId = [command.arguments objectAtIndex:0];
358
- BOOL autoShow = [[command argumentAtIndex:1] boolValue];
359
- auto_Show = autoShow;
360
- adFormat = 4;
361
- if (adFormat == 4){ GADRequest *request = [GADRequest request];
362
- [GADRewardedInterstitialAd
363
- loadWithAdUnitID:adUnitId
364
- request:request
365
- completionHandler:^(GADRewardedInterstitialAd *ad, NSError *error) {
366
- if (error) {
367
- NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
368
- return;
369
- }
370
- self.rewardedInterstitialAd = ad; isAdSkip = 1;
371
- NSLog(@"Rewarded ad loaded.");
372
- self.rewardedInterstitialAd.fullScreenContentDelegate = self;
373
- [self fireEvent:@"" event:@"on.rewardedInt.loaded" withData:nil]; if (auto_Show){ if (self.rewardedInterstitialAd && [self.rewardedInterstitialAd canPresentFromRootViewController:self.viewController error:nil]) { [self.rewardedInterstitialAd presentFromRootViewController:self.viewController
374
- userDidEarnRewardHandler:^{
375
- GADAdReward *reward =
376
- self.rewardedInterstitialAd.adReward;
377
- [self fireEvent:@"" event:@"on.rewardedInt.userEarnedReward" withData:nil];
378
- isAdSkip = 2;
379
- NSString *rewardMessage = [NSString stringWithFormat:@"Reward received with "
380
- @"currency %@ , amount %ld",
381
- reward.type, [reward.amount longValue]];
382
- NSLog(@"%@", rewardMessage); }]; } else { [self fireEvent:@"" event:@"on.rewardedInt.failed.show" withData:nil];
383
- } } }];
384
- }
385
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
386
- [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
387
- }-(void)showRewardedInterstitialAd:(CDVInvokedUrlCommand *)command {
388
- CDVPluginResult *pluginResult;
389
- NSString *callbackId = command.callbackId;
390
- if (self.rewardedInterstitialAd && [self.rewardedInterstitialAd canPresentFromRootViewController:self.viewController error:nil]) { [self.rewardedInterstitialAd presentFromRootViewController:self.viewController
391
- userDidEarnRewardHandler:^{
392
- GADAdReward *reward =
393
- self.rewardedInterstitialAd.adReward;
394
- [self fireEvent:@"" event:@"on.rewardedInt.userEarnedReward" withData:nil];
395
- isAdSkip = 2;
396
- NSString *rewardMessage = [NSString stringWithFormat:@"Reward received with "
397
- @"currency %@ , amount %ld",
398
- reward.type, [reward.amount longValue]];
399
- NSLog(@"%@", rewardMessage); }]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; } else {
400
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
401
- [self fireEvent:@"" event:@"on.rewardedInt.failed.show" withData:nil];
402
- } [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
403
- }- (void)loadRewardedAd:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult;
404
- NSString *callbackId = command.callbackId;
405
- NSString* adUnitId = [command.arguments objectAtIndex:0];
406
- BOOL autoShow = [[command argumentAtIndex:1] boolValue];
407
- auto_Show = autoShow;
408
- adFormat = 3;
409
- if (adFormat == 3){
410
- GADRequest *request = [GADRequest request];
411
- [GADRewardedAd
412
- loadWithAdUnitID:adUnitId
413
- request:request
414
- completionHandler:^(GADRewardedAd *ad, NSError *error) {
415
- if (error) {
416
- NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
417
- return;
418
- }
419
- self.rewardedAd = ad;
420
- NSLog(@"Rewarded ad loaded.");
421
- isAdSkip = 0;
422
- self.rewardedAd.fullScreenContentDelegate = self;
423
- [self fireEvent:@"" event:@"on.rewarded.loaded" withData:nil]; if (auto_Show){ if (self.rewardedAd && [self.rewardedAd canPresentFromRootViewController:self.viewController error:nil]) { [self.rewardedAd presentFromRootViewController:self.viewController
424
- userDidEarnRewardHandler:^{
425
- GADAdReward *reward =
426
- self.rewardedAd.adReward;
427
- [self fireEvent:@"" event:@"on.reward.userEarnedReward" withData:nil];
428
- isAdSkip = 2;
429
- NSString *rewardMessage = [NSString stringWithFormat:@"Reward received with currency %@ , amount %lf", reward.type, [reward.amount doubleValue]];
430
- NSLog(@"%@", rewardMessage); }]; } else { [self fireEvent:@"" event:@"on.rewarded.failed.show" withData:nil];
431
- } } }];
432
- }
433
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
434
- [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
435
- }-(void)showRewardedAd:(CDVInvokedUrlCommand *)command {
436
- CDVPluginResult *pluginResult;
437
- NSString *callbackId = command.callbackId;
438
- if (self.rewardedAd && [self.rewardedAd canPresentFromRootViewController:self.viewController error:nil]) { [self.rewardedAd presentFromRootViewController:self.viewController
439
- userDidEarnRewardHandler:^{
440
- GADAdReward *reward =
441
- self.rewardedAd.adReward;
442
- [self fireEvent:@"" event:@"on.reward.userEarnedReward" withData:nil];
443
- isAdSkip = 2;
444
- NSString *rewardMessage = [NSString stringWithFormat:@"Reward received with currency %@ , amount %lf", reward.type, [reward.amount doubleValue]];
445
- NSLog(@"%@", rewardMessage); }]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; } else {
446
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
447
- [self fireEvent:@"" event:@"on.rewarded.failed.show" withData:nil];
448
- } [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
449
- }- (void) fireEvent:(NSString *)obj event:(NSString *)eventName withData:(NSString *)jsonStr {
450
- NSString* js;
451
- if(obj && [obj isEqualToString:@"window"]) {
452
- js = [NSString stringWithFormat:@"var evt=document.createEvent(\"UIEvents\");evt.initUIEvent(\"%@\",true,false,window,0);window.dispatchEvent(evt);", eventName];
453
- } else if(jsonStr && [jsonStr length]>0) {
454
- js = [NSString stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@',%@);", eventName, jsonStr];
455
- } else {
456
- js = [NSString stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@');", eventName];
457
- }
458
- [self.commandDelegate evalJs:js];
856
+ return;
857
+ }
858
+
859
+ if (collapsible != nil && [collapsible length] > 0) {
860
+ enableCollapsible = YES;
861
+ } else {
862
+ enableCollapsible = NO;
863
+ }
864
+
865
+ if (autoResize) {
866
+
867
+ isAutoResize = YES;
868
+ }
869
+
870
+ if (adFormat == 3) {
871
+ dispatch_async(dispatch_get_main_queue(), ^{
872
+ UIView *parentView = [self.webView superview];
873
+ CGRect frame = self.bannerView.frame;
874
+
875
+ if (@available(iOS 11.0, *)) {
876
+ UIEdgeInsets safeAreaInsets = self.bannerView.safeAreaInsets;
877
+ frame = UIEdgeInsetsInsetRect(frame, safeAreaInsets);
878
+ }
879
+
880
+ self.viewWidth = frame.size.width;
881
+
882
+ auto_Show = autoShow;
883
+ adWidth = self.viewWidth;
884
+
885
+ Position = position;
886
+
887
+ GADAdSize sizes = [self __AdSizeFromString:size];
888
+ self.bannerView = [[GADBannerView alloc] initWithAdSize:sizes];
889
+
890
+ GADRequest *request = [GADRequest request];
891
+ GADExtras *extras = [[GADExtras alloc] init];
892
+
893
+ if (enableCollapsible) {
894
+ extras.additionalParameters = @{@"collapsible" : collapsible};
895
+ }
896
+
897
+ [request registerAdNetworkExtras:extras];
898
+
899
+ self.bannerView.adUnitID = adUnitId;
900
+ self.bannerView.rootViewController = self.viewController;
901
+ self.bannerView.delegate = self;
902
+ [self.bannerView loadRequest:request];
903
+ self.bannerView.hidden = YES;
904
+ [parentView addSubview:self.bannerView];
905
+ [parentView bringSubviewToFront:self.bannerView];
906
+ });
907
+
908
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
909
+ } else {
910
+ // NSLog(@"Admob Option invalid for banner");
911
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
912
+ }
913
+
914
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
915
+ }
916
+
917
+ - (GADAdSize)__AdSizeFromString:(NSString *)size {
918
+
919
+ if (self.viewWidth == 0) {
920
+ self.viewWidth = [UIScreen mainScreen].bounds.size.width;
921
+ }
922
+
923
+ if ([size isEqualToString:@"responsive_adaptive"]) {
924
+ return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(
925
+ self.viewWidth);
926
+ } else if ([size isEqualToString:@"in_line_adaptive"]) {
927
+ return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(
928
+ self.viewWidth);
929
+ } else if ([size isEqualToString:@"banner"]) {
930
+ return GADAdSizeBanner;
931
+ } else if ([size isEqualToString:@"large_banner"]) {
932
+ return GADAdSizeLargeBanner;
933
+ } else if ([size isEqualToString:@"full_banner"]) {
934
+ return GADAdSizeFullBanner;
935
+ } else if ([size isEqualToString:@"leaderboard"]) {
936
+ return GADAdSizeLeaderboard;
937
+ } else {
938
+ return GADAdSizeBanner;
939
+ }
940
+ }
941
+
942
+ - (void)showBannerAd:(CDVInvokedUrlCommand *)command {
943
+ CDVPluginResult *pluginResult;
944
+ NSString *callbackId = command.callbackId;
945
+ if (self.bannerView) {
946
+ self.bannerView.hidden = NO;
947
+ [self addBannerViewToView:command];
948
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
949
+ } else {
950
+ [self fireEvent:@""
951
+ event:@"on."
952
+ @"bann"
953
+ @"er."
954
+ @"fail"
955
+ @"ed."
956
+ @"show"
957
+ withData:nil];
958
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
959
+ }
960
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
961
+ }
962
+
963
+ - (void)addBannerViewToView:(CDVInvokedUrlCommand *)command {
964
+ bannerView.translatesAutoresizingMaskIntoConstraints = NO;
965
+ [self.viewController.view addSubview:bannerView];
966
+ if ([Position isEqualToString:@"bottom-center"]) {
967
+ [self.viewController.view addConstraints:@[
968
+ [NSLayoutConstraint
969
+ constraintWithItem:bannerView
970
+ attribute:NSLayoutAttributeBottom
971
+ relatedBy:NSLayoutRelationEqual
972
+ toItem:self.viewController.view.safeAreaLayoutGuide
973
+ attribute:NSLayoutAttributeBottom
974
+ multiplier:1
975
+ constant:0],
976
+ [NSLayoutConstraint constraintWithItem:bannerView
977
+ attribute:NSLayoutAttributeCenterX
978
+ relatedBy:NSLayoutRelationEqual
979
+ toItem:self.viewController.view
980
+ attribute:NSLayoutAttributeCenterX
981
+ multiplier:1
982
+ constant:0]
983
+ ]];
984
+ } else if ([Position isEqualToString:@"top-center"]) {
985
+
986
+ [self.viewController.view addConstraints:@[
987
+ [NSLayoutConstraint
988
+ constraintWithItem:bannerView
989
+ attribute:NSLayoutAttributeTop
990
+ relatedBy:NSLayoutRelationEqual
991
+ toItem:self.viewController.view.safeAreaLayoutGuide
992
+ attribute:NSLayoutAttributeTop
993
+ multiplier:1
994
+ constant:0],
995
+ [NSLayoutConstraint constraintWithItem:bannerView
996
+ attribute:NSLayoutAttributeCenterX
997
+ relatedBy:NSLayoutRelationEqual
998
+ toItem:self.viewController.view
999
+ attribute:NSLayoutAttributeCenterX
1000
+ multiplier:1
1001
+ constant:0]
1002
+ ]];
1003
+
1004
+ } else {
1005
+ [self.viewController.view addConstraints:@[
1006
+ [NSLayoutConstraint
1007
+ constraintWithItem:bannerView
1008
+ attribute:NSLayoutAttributeBottom
1009
+ relatedBy:NSLayoutRelationEqual
1010
+ toItem:self.viewController.view.safeAreaLayoutGuide
1011
+ attribute:NSLayoutAttributeTop
1012
+ multiplier:1
1013
+ constant:0],
1014
+ [NSLayoutConstraint constraintWithItem:bannerView
1015
+ attribute:NSLayoutAttributeCenterX
1016
+ relatedBy:NSLayoutRelationEqual
1017
+ toItem:self.viewController.view
1018
+ attribute:NSLayoutAttributeCenterX
1019
+ multiplier:1
1020
+ constant:0]
1021
+ ]];
1022
+ }
1023
+ }
1024
+ - (void)hideBannerAd:(CDVInvokedUrlCommand *)command {
1025
+ CDVPluginResult *pluginResult;
1026
+ NSString *callbackId = command.callbackId;
1027
+ if (self.bannerView) {
1028
+ dispatch_async(dispatch_get_main_queue(), ^{
1029
+ self.bannerView.hidden = YES;
1030
+ [self fireEvent:@"" event:@"on.banner.hide" withData:nil];
1031
+ });
1032
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1033
+ } else {
1034
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
1035
+ }
1036
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1037
+ }
1038
+ - (void)removeBannerAd:(CDVInvokedUrlCommand *)command {
1039
+ CDVPluginResult *pluginResult;
1040
+ NSString *callbackId = command.callbackId;
1041
+ if (self.bannerView) {
1042
+ dispatch_async(dispatch_get_main_queue(), ^{
1043
+ self.bannerView.hidden = YES;
1044
+ [self.bannerView removeFromSuperview];
1045
+ self.bannerView = nil;
1046
+ [self fireEvent:@"" event:@"on.banner.remove" withData:nil];
1047
+ });
1048
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1049
+ } else {
1050
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
1051
+ }
1052
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1053
+ }
1054
+ - (void)loadAppOpenAd:(CDVInvokedUrlCommand *)command {
1055
+ CDVPluginResult *pluginResult;
1056
+ NSString *callbackId = command.callbackId;
1057
+ NSDictionary *options = [command.arguments objectAtIndex:0];
1058
+ NSString *adUnitId = [options valueForKey:@"adUnitId"];
1059
+ BOOL autoShow = [[options valueForKey:@"autoShow"] boolValue];
1060
+ auto_Show = autoShow;
1061
+ adFormat = 1;
1062
+ self.appOpenAd = nil;
1063
+ if (adFormat == 1) {
1064
+ dispatch_async(dispatch_get_main_queue(), ^{
1065
+ GADRequest *request = [GADRequest request];
1066
+ GADExtras *extras = [[GADExtras alloc] init];
1067
+ // extras.additionalParameters = @{@"npa" : Npa}; // Deprecated
1068
+ [request registerAdNetworkExtras:extras];
1069
+ [GADAppOpenAd
1070
+ loadWithAdUnitID:adUnitId
1071
+ request:request
1072
+ completionHandler:^(GADAppOpenAd *ad, NSError *error) {
1073
+ if (error) {
1074
+ [self fireEvent:@""
1075
+ event:@"on.appOpenAd.failed.loaded"
1076
+ withData:nil];
1077
+
1078
+ return;
1079
+ }
1080
+ self.appOpenAd = ad;
1081
+ self.appOpenAd.fullScreenContentDelegate = self;
1082
+ [self fireEvent:@"" event:@"on.appOpenAd.loaded" withData:nil];
1083
+ if (auto_Show) {
1084
+ if (self.appOpenAd &&
1085
+ [self.appOpenAd
1086
+ canPresentFromRootViewController:self.viewController
1087
+ error:nil]) {
1088
+ [self.appOpenAd
1089
+ presentFromRootViewController:self.viewController];
1090
+ } else {
1091
+ [self fireEvent:@""
1092
+ event:@"on.appOpenAd.failed.show"
1093
+ withData:nil];
1094
+ }
1095
+ }
1096
+ }];
1097
+ });
1098
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1099
+ }
1100
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1101
+ }
1102
+ - (void)showAppOpenAd:(CDVInvokedUrlCommand *)command {
1103
+ CDVPluginResult *pluginResult;
1104
+ NSString *callbackId = command.callbackId;
1105
+ if (self.appOpenAd &&
1106
+ [self.appOpenAd canPresentFromRootViewController:self.viewController
1107
+ error:nil]) {
1108
+ [self.appOpenAd presentFromRootViewController:self.viewController];
1109
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1110
+ } else {
1111
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
1112
+ [self fireEvent:@""
1113
+ event:@"on."
1114
+ @"appO"
1115
+ @"penA"
1116
+ @"d."
1117
+ @"fail"
1118
+ @"ed."
1119
+ @"show"
1120
+ withData:nil];
1121
+ }
1122
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1123
+ }
1124
+ - (void)loadInterstitialAd:(CDVInvokedUrlCommand *)command {
1125
+ CDVPluginResult *pluginResult;
1126
+ NSString *callbackId = command.callbackId;
1127
+ NSDictionary *options = [command.arguments objectAtIndex:0];
1128
+ NSString *adUnitId = [options valueForKey:@"adUnitId"];
1129
+ BOOL autoShow = [[options valueForKey:@"autoShow"] boolValue];
1130
+ auto_Show = autoShow;
1131
+ adFormat = 2;
1132
+ if (adFormat == 2) {
1133
+ dispatch_async(dispatch_get_main_queue(), ^{
1134
+ GADRequest *request = [GADRequest request];
1135
+ [GADInterstitialAd
1136
+ loadWithAdUnitID:adUnitId
1137
+ request:request
1138
+ completionHandler:^(GADInterstitialAd *ad, NSError *error) {
1139
+ if (error) {
1140
+
1141
+ }
1142
+ self.interstitial = ad;
1143
+ self.interstitial.fullScreenContentDelegate = self;
1144
+ [self fireEvent:@"" event:@"on.interstitial.loaded" withData:nil];
1145
+ if (auto_Show) {
1146
+ if (self.interstitial &&
1147
+ [self.interstitial
1148
+ canPresentFromRootViewController:self.viewController
1149
+ error:nil]) {
1150
+ [self.interstitial
1151
+ presentFromRootViewController:self.viewController];
1152
+ } else {
1153
+ [self fireEvent:@""
1154
+ event:@"on.interstitial.failed.show"
1155
+ withData:nil];
1156
+ }
1157
+ }
1158
+ }];
1159
+ });
1160
+ }
1161
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1162
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1163
+ }
1164
+ - (void)showInterstitialAd:(CDVInvokedUrlCommand *)command {
1165
+ CDVPluginResult *pluginResult;
1166
+ NSString *callbackId = command.callbackId;
1167
+ if (self.interstitial &&
1168
+ [self.interstitial canPresentFromRootViewController:self.viewController
1169
+ error:nil]) {
1170
+ [self.interstitial presentFromRootViewController:self.viewController];
1171
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1172
+ } else {
1173
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
1174
+ [self fireEvent:@""
1175
+ event:@"on."
1176
+ @"inte"
1177
+ @"rsti"
1178
+ @"tial"
1179
+ @".fai"
1180
+ @"led."
1181
+ @"show"
1182
+ withData:nil];
1183
+ }
1184
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1185
+ }
1186
+ - (void)loadRewardedInterstitialAd:(CDVInvokedUrlCommand *)command {
1187
+ CDVPluginResult *pluginResult;
1188
+ NSString *callbackId = command.callbackId;
1189
+
1190
+ NSDictionary *options = [command.arguments objectAtIndex:0];
1191
+ NSString *adUnitId = [options valueForKey:@"adUnitId"];
1192
+ BOOL autoShow = [[options valueForKey:@"autoShow"] boolValue];
1193
+
1194
+ auto_Show = autoShow;
1195
+ adFormat = 4;
1196
+ if (adFormat == 4) {
1197
+ dispatch_async(dispatch_get_main_queue(), ^{
1198
+ GADRequest *request = [GADRequest request];
1199
+ [GADRewardedInterstitialAd
1200
+ loadWithAdUnitID:adUnitId
1201
+ request:request
1202
+ completionHandler:^(GADRewardedInterstitialAd *ad, NSError *error) {
1203
+ if (error) {
1204
+ /* NSLog(@"Rewarded ad failed to load with error: %@",
1205
+ [error localizedDescription]); */
1206
+ return;
1207
+ }
1208
+ self.rewardedInterstitialAd = ad;
1209
+ isAdSkip = 1;
1210
+ // NSLog(@"Rewarded ad loaded.");
1211
+ self.rewardedInterstitialAd.fullScreenContentDelegate = self;
1212
+ [self fireEvent:@"" event:@"on.rewardedInt.loaded" withData:nil];
1213
+ if (auto_Show) {
1214
+ if (self.rewardedInterstitialAd &&
1215
+ [self.rewardedInterstitialAd
1216
+ canPresentFromRootViewController:self.viewController
1217
+ error:nil]) {
1218
+ [self.rewardedInterstitialAd
1219
+ presentFromRootViewController:self.viewController
1220
+ userDidEarnRewardHandler:^{
1221
+ GADAdReward *reward =
1222
+ self.rewardedInterstitialAd.adReward;
1223
+ [self fireEvent:@""
1224
+ event:@"on.rewardedInt."
1225
+ @"userEarnedReward"
1226
+ withData:nil];
1227
+ isAdSkip = 2;
1228
+ NSString *rewardMessage = [NSString
1229
+ stringWithFormat:@"Reward received with "
1230
+ @"currency %@ , amount %ld",
1231
+ reward.type,
1232
+ [reward.amount longValue]];
1233
+ NSLog(@"%@", rewardMessage);
1234
+ }];
1235
+ } else {
1236
+ [self fireEvent:@""
1237
+ event:@"on.rewardedInt.failed.show"
1238
+ withData:nil];
1239
+ }
1240
+ }
1241
+ }];
1242
+ });
1243
+ }
1244
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1245
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1246
+ }
1247
+ - (void)showRewardedInterstitialAd:(CDVInvokedUrlCommand *)command {
1248
+ CDVPluginResult *pluginResult;
1249
+ NSString *callbackId = command.callbackId;
1250
+ if (self.rewardedInterstitialAd &&
1251
+ [self.rewardedInterstitialAd
1252
+ canPresentFromRootViewController:self.viewController
1253
+ error:nil]) {
1254
+ [self.rewardedInterstitialAd
1255
+ presentFromRootViewController:self.viewController
1256
+ userDidEarnRewardHandler:^{
1257
+ GADAdReward *reward = self.rewardedInterstitialAd.adReward;
1258
+ [self fireEvent:@""
1259
+ event:@"on.rewardedInt.userEarnedReward"
1260
+ withData:nil];
1261
+ isAdSkip = 2;
1262
+ NSString *rewardMessage = [NSString
1263
+ stringWithFormat:@"Reward received with "
1264
+ @"currency %@ , amount %ld",
1265
+ reward.type, [reward.amount longValue]];
1266
+ NSLog(@"%"
1267
+ @"@",
1268
+ rewardMessage);
1269
+ }];
1270
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1271
+ } else {
1272
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
1273
+ [self fireEvent:@""
1274
+ event:@"on."
1275
+ @"rewa"
1276
+ @"rded"
1277
+ @"Int."
1278
+ @"fail"
1279
+ @"ed."
1280
+ @"show"
1281
+ withData:nil];
1282
+ }
1283
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1284
+ }
1285
+ - (void)loadRewardedAd:(CDVInvokedUrlCommand *)command {
1286
+ CDVPluginResult *pluginResult;
1287
+ NSString *callbackId = command.callbackId;
1288
+ NSDictionary *options = [command.arguments objectAtIndex:0];
1289
+ NSString *adUnitId = [options valueForKey:@"adUnitId"];
1290
+ BOOL autoShow = [[options valueForKey:@"autoShow"] boolValue];
1291
+ auto_Show = autoShow;
1292
+ adFormat = 3;
1293
+ if (adFormat == 3) {
1294
+ dispatch_async(dispatch_get_main_queue(), ^{
1295
+ GADRequest *request = [GADRequest request];
1296
+ [GADRewardedAd
1297
+ loadWithAdUnitID:adUnitId
1298
+ request:request
1299
+ completionHandler:^(GADRewardedAd *ad, NSError *error) {
1300
+ if (error) {
1301
+ /* NSLog(@"Rewarded ad failed to load with error: %@",
1302
+ [error localizedDescription]); */
1303
+ return;
459
1304
  }
1305
+ self.rewardedAd = ad;
1306
+ // NSLog(@"Rewarded ad loaded.");
1307
+ isAdSkip = 0;
1308
+ self.rewardedAd.fullScreenContentDelegate = self;
1309
+ [self fireEvent:@"" event:@"on.rewarded.loaded" withData:nil];
1310
+ if (auto_Show) {
1311
+ if (self.rewardedAd &&
1312
+ [self.rewardedAd
1313
+ canPresentFromRootViewController:self.viewController
1314
+ error:nil]) {
1315
+ [self.rewardedAd
1316
+ presentFromRootViewController:self.viewController
1317
+ userDidEarnRewardHandler:^{
1318
+ GADAdReward *reward = self.rewardedAd.adReward;
1319
+ [self fireEvent:@""
1320
+ event:@"on.reward.userEarnedReward"
1321
+ withData:nil];
1322
+ isAdSkip = 2;
1323
+ NSString *rewardMessage = [NSString
1324
+ stringWithFormat:
1325
+ @"Reward received with currency "
1326
+ @"%@ , amount %lf",
1327
+ reward.type, [reward.amount doubleValue]];
1328
+ NSLog(@"%@", rewardMessage);
1329
+ }];
1330
+ } else {
1331
+ [self fireEvent:@""
1332
+ event:@"on.rewarded.failed.show"
1333
+ withData:nil];
1334
+ }
1335
+ }
1336
+ }];
1337
+ });
1338
+ }
1339
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1340
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1341
+ }
1342
+ - (void)showRewardedAd:(CDVInvokedUrlCommand *)command {
1343
+ CDVPluginResult *pluginResult;
1344
+ NSString *callbackId = command.callbackId;
1345
+ if (self.rewardedAd &&
1346
+ [self.rewardedAd canPresentFromRootViewController:self.viewController
1347
+ error:nil]) {
1348
+ [self.rewardedAd
1349
+ presentFromRootViewController:self.viewController
1350
+ userDidEarnRewardHandler:^{
1351
+ GADAdReward *reward = self.rewardedAd.adReward;
1352
+ [self fireEvent:@""
1353
+ event:@"on.reward.userEarnedReward"
1354
+ withData:nil];
1355
+ isAdSkip = 2;
1356
+ NSString *rewardMessage = [NSString
1357
+ stringWithFormat:
1358
+ @"Reward received with currency %@ , amount %lf",
1359
+ reward.type, [reward.amount doubleValue]];
1360
+ NSLog(@"%"
1361
+ @"@",
1362
+ rewardMessage);
1363
+ }];
1364
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1365
+ } else {
1366
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
1367
+ [self fireEvent:@""
1368
+ event:@"on."
1369
+ @"rewa"
1370
+ @"rded"
1371
+ @".fai"
1372
+ @"led."
1373
+ @"show"
1374
+ withData:nil];
1375
+ }
1376
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1377
+ }
1378
+ - (void)fireEvent:(NSString *)obj
1379
+ event:(NSString *)eventName
1380
+ withData:(NSString *)jsonStr {
1381
+ NSString *js;
1382
+ if (obj && [obj isEqualToString:@"windo"
1383
+ @"w"]) {
1384
+ js = [NSString stringWithFormat:@"var "
1385
+ @"evt="
1386
+ @"document"
1387
+ @".createE"
1388
+ @"vent("
1389
+ @"\"UIEven"
1390
+ @"ts\");"
1391
+ @"evt."
1392
+ @"initUIEv"
1393
+ @"ent("
1394
+ @"\"%@\","
1395
+ @"true,"
1396
+ @"false,"
1397
+ @"window,"
1398
+ @"0);"
1399
+ @"window."
1400
+ @"dispatch"
1401
+ @"Event("
1402
+ @"evt);",
1403
+ eventName];
1404
+ } else if (jsonStr && [jsonStr length] > 0) {
1405
+ js = [NSString stringWithFormat:@"javascri"
1406
+ @"pt:"
1407
+ @"cordova."
1408
+ @"fireDocu"
1409
+ @"mentEven"
1410
+ @"t('%@',%"
1411
+ @"@);",
1412
+ eventName, jsonStr];
1413
+ } else {
1414
+ js = [NSString stringWithFormat:@"javascri"
1415
+ @"pt:"
1416
+ @"cordova."
1417
+ @"fireDocu"
1418
+ @"mentEven"
1419
+ @"t('%@')"
1420
+ @";",
1421
+ eventName];
1422
+ }
1423
+ [self.commandDelegate evalJs:js];
1424
+ }
1425
+
1426
+ - (NSString *)__getAdMobDeviceId {
1427
+ NSUUID *adid = [[ASIdentifierManager sharedManager] advertisingIdentifier];
1428
+ return [self __sha256:adid.UUIDString];
1429
+ }
1430
+
1431
+ - (NSString *)__sha256:(NSString *)string {
1432
+ CC_SHA256_CTX sha256Context;
1433
+ CC_SHA256_Init(&sha256Context);
1434
+ NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
1435
+ CC_SHA256_Update(&sha256Context, [data bytes], (CC_LONG)[data length]);
1436
+ unsigned char digest[CC_SHA256_DIGEST_LENGTH];
1437
+ CC_SHA256_Final(digest, &sha256Context);
1438
+
1439
+ NSMutableString *hexString =
1440
+ [NSMutableString stringWithCapacity:(CC_SHA256_DIGEST_LENGTH * 2)];
1441
+ for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) {
1442
+ [hexString appendFormat:@"%02x", digest[i]];
1443
+ }
1444
+
1445
+ return hexString;
1446
+ }
1447
+
460
1448
  #pragma mark GADBannerViewDelegate implementation
461
- -(void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
462
- [self fireEvent:@"" event:@"on.banner.load" withData:nil];
463
- NSLog(@"bannerViewDidReceiveAd");
464
- if (auto_Show){
465
- if(self.bannerView) {
466
- [self addBannerViewToView:command];
467
- self.bannerView.hidden = NO;
468
- }
469
- } else { [self fireEvent:@"" event:@"on.banner.failed.show" withData:nil];
470
- }}- (void)bannerView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error {
471
- [self fireEvent:@"" event:@"on.banner.failed.load" withData:nil];
472
- NSLog(@"bannerView:didFailToReceiveAdWithError: %@", [error localizedDescription]);
473
- }- (void)bannerViewDidRecordImpression:(GADBannerView *)bannerView {
474
- [self fireEvent:@"" event:@"on.banner.impression" withData:nil];
475
- NSLog(@"bannerViewDidRecordImpression");
476
- }- (void)bannerViewWillPresentScreen:(GADBannerView *)bannerView {
477
- [self fireEvent:@"" event:@"on.banner.open" withData:nil];
478
- NSLog(@"bannerViewWillPresentScreen");
479
- }- (void)bannerViewWillDismissScreen:(GADBannerView *)bannerView {
480
- [self fireEvent:@"" event:@"on.banner.close" withData:nil];
481
- NSLog(@"bannerViewWillDismissScreen");
482
- }- (void)bannerViewDidDismissScreen:(GADBannerView *)bannerView {
483
- [self fireEvent:@"" event:@"on.banner.did.dismiss" withData:nil];
484
- NSLog(@"bannerViewDidDismissScreen");
1449
+ - (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
1450
+
1451
+ NSString *collapsibleStatus =
1452
+ bannerView.isCollapsible ? @"collapsible" : @"not collapsible";
1453
+ NSDictionary *eventData = @{@"collapsible" : collapsibleStatus};
1454
+ NSError *error;
1455
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:eventData
1456
+ options:0
1457
+ error:&error];
1458
+
1459
+ if (!jsonData) {
1460
+ // NSLog(@"Failed to serialize event data: %@", error);
1461
+ } else {
1462
+ NSString *jsonString = [[NSString alloc] initWithData:jsonData
1463
+ encoding:NSUTF8StringEncoding];
1464
+ [self fireEvent:@"" event:@"on.is.collapsible" withData:jsonString];
1465
+ }
1466
+
1467
+ [self fireEvent:@""
1468
+ event:@"on."
1469
+ @"banner"
1470
+ @".load"
1471
+ withData:nil];
1472
+
1473
+ if (auto_Show) {
1474
+ if (self.bannerView) {
1475
+ [self addBannerViewToView:command];
1476
+ self.bannerView.hidden = NO;
485
1477
  }
1478
+ } else {
1479
+ [self fireEvent:@""
1480
+ event:@"on."
1481
+ @"bann"
1482
+ @"er."
1483
+ @"fail"
1484
+ @"ed."
1485
+ @"show"
1486
+ withData:nil];
1487
+ }
1488
+ }
1489
+ - (void)bannerView:(GADBannerView *)bannerView
1490
+ didFailToReceiveAdWithError:(NSError *)error {
1491
+ [self fireEvent:@""
1492
+ event:@"on."
1493
+ @"banner"
1494
+ @".faile"
1495
+ @"d.load"
1496
+ withData:nil];
1497
+
1498
+ }
1499
+ - (void)bannerViewDidRecordImpression:(GADBannerView *)bannerView {
1500
+ [self fireEvent:@""
1501
+ event:@"on."
1502
+ @"banner"
1503
+ @".impre"
1504
+ @"ssion"
1505
+ withData:nil];
1506
+
1507
+ }
1508
+ - (void)bannerViewWillPresentScreen:(GADBannerView *)bannerView {
1509
+ [self fireEvent:@""
1510
+ event:@"on."
1511
+ @"banner"
1512
+ @".open"
1513
+ withData:nil];
1514
+
1515
+ }
1516
+ - (void)bannerViewWillDismissScreen:(GADBannerView *)bannerView {
1517
+ [self fireEvent:@""
1518
+ event:@"on."
1519
+ @"banner"
1520
+ @".close"
1521
+ withData:nil];
1522
+
1523
+ }
1524
+ - (void)bannerViewDidDismissScreen:(GADBannerView *)bannerView {
1525
+ [self fireEvent:@""
1526
+ event:@"on."
1527
+ @"banner"
1528
+ @".did."
1529
+ @"dismis"
1530
+ @"s"
1531
+ withData:nil];
1532
+
1533
+ }
486
1534
  #pragma GADFullScreeContentDelegate implementation
487
- - (void)adWillPresentFullScreenContent:(id)ad { if (adFormat == 1){ [self fireEvent:@"" event:@"on.appOpenAd.show" withData:nil];
488
- NSLog(@"Ad will present full screen content App Open Ad."); } else if (adFormat == 2){ [self fireEvent:@"" event:@"on.interstitial.show" withData:nil];
489
- [self fireEvent:@"" event:@"onPresentAd" withData:nil];
490
- NSLog(@"Ad will present full screen content interstitial."); } else if (adFormat == 3) { [self fireEvent:@"" event:@"on.rewarded.show" withData:nil];
491
- isAdSkip = 1;
492
- NSLog(@"Ad will present full screen content rewarded."); } else if (adFormat == 4) {
493
- isAdSkip = 1;
494
- [self fireEvent:@"" event:@"on.rewardedInt.showed" withData:nil];
495
- NSLog(@"Ad will present full screen content interstitial rewarded.");
496
- }}- (void)ad:(id)ad didFailToPresentFullScreenContentWithError:(NSError *)error { if (adFormat == 1){ [self fireEvent:@"" event:@"on.appOpenAd.failed.loaded" withData:nil];
497
- NSLog(@"Ad failed to present full screen content with error App Open Ad %@.", [error localizedDescription]); } else if (adFormat == 2){
498
- [self fireEvent:@"" event:@"on.interstitial.failed.load" withData:nil];
499
- NSLog(@"Ad failed to present full screen content with error interstitial %@.", [error localizedDescription]);
500
- } else if (adFormat == 3) { [self fireEvent:@"" event:@"on.rewarded.failed.load" withData:nil];
501
- NSLog(@"Ad failed to present full screen content with error rewarded %@.", [error localizedDescription]); } else if (adFormat == 4) { [self fireEvent:@"" event:@"on.rewardedInt.failed.load" withData:nil];
502
- NSLog(@"Ad failed to present full screen content with error interstitial rewarded %@.", [error localizedDescription]); }}- (void)adDidDismissFullScreenContent:(id)ad { if (adFormat == 1){ [self fireEvent:@"" event:@"on.appOpenAd.dismissed" withData:nil];
503
- NSLog(@"Ad did dismiss full screen content App Open Ad."); } else if (adFormat == 2){
504
- [self fireEvent:@"" event:@"on.interstitial.dismissed" withData:nil];
505
- NSLog(@"Ad did dismiss full screen content interstitial.");
506
- } else if (adFormat == 3) { [self fireEvent:@"" event:@"on.rewarded.dismissed" withData:nil]; if (isAdSkip != 2) {
507
- [self fireEvent:@"" event:@"on.rewarded.ad.skip" withData:nil];
508
- }
509
- NSLog(@"Ad did dismiss full screen content rewarded."); } else if (adFormat == 4) {
510
- if (isAdSkip != 2) {
511
- [self fireEvent:@"" event:@"on.rewardedInt.ad.skip" withData:nil];
512
- }
513
- [self fireEvent:@"" event:@"on.rewardedInt.dismissed" withData:nil];
514
- NSLog(@"Ad did dismiss full screen content interstitial rewarded."); }}
1535
+ - (void)adWillPresentFullScreenContent:(id)ad {
1536
+ if (adFormat == 1) {
1537
+ [self fireEvent:@""
1538
+ event:@"on."
1539
+ @"appO"
1540
+ @"penA"
1541
+ @"d."
1542
+ @"show"
1543
+ withData:nil];
1544
+ /* NSLog(@"Ad will "
1545
+ @"present "
1546
+ @"full screen "
1547
+ @"content App "
1548
+ @"Open Ad.");
1549
+ */
1550
+ } else if (adFormat == 2) {
1551
+ [self fireEvent:@""
1552
+ event:@"on."
1553
+ @"inte"
1554
+ @"rsti"
1555
+ @"tial"
1556
+ @".sho"
1557
+ @"w"
1558
+ withData:nil];
1559
+ [self fireEvent:@""
1560
+ event:@"onPr"
1561
+ @"esen"
1562
+ @"tAd"
1563
+ withData:nil];
1564
+ /* NSLog(@"Ad will "
1565
+ @"present "
1566
+ @"full screen "
1567
+ @"content "
1568
+ @"interstitial"
1569
+ @"."); */
1570
+ } else if (adFormat == 3) {
1571
+ [self fireEvent:@""
1572
+ event:@"on."
1573
+ @"rewa"
1574
+ @"rded"
1575
+ @".sho"
1576
+ @"w"
1577
+ withData:nil];
1578
+ isAdSkip = 1;
1579
+ /* NSLog(@"Ad will "
1580
+ @"present "
1581
+ @"full screen "
1582
+ @"content "
1583
+ @"rewarded."); */
1584
+ } else if (adFormat == 4) {
1585
+ isAdSkip = 1;
1586
+ [self fireEvent:@""
1587
+ event:@"on."
1588
+ @"rewa"
1589
+ @"rded"
1590
+ @"Int."
1591
+ @"show"
1592
+ @"ed"
1593
+ withData:nil];
1594
+ /* NSLog(@"Ad will "
1595
+ @"present "
1596
+ @"full screen "
1597
+ @"content "
1598
+ @"interstitial"
1599
+ @" rewarded."); */
1600
+ }
1601
+ }
1602
+ - (void)ad:(id)ad didFailToPresentFullScreenContentWithError:(NSError *)error {
1603
+ if (adFormat == 1) {
1604
+ [self fireEvent:@""
1605
+ event:@"on."
1606
+ @"appO"
1607
+ @"penA"
1608
+ @"d."
1609
+ @"fail"
1610
+ @"ed."
1611
+ @"load"
1612
+ @"ed"
1613
+ withData:nil];
1614
+ /* NSLog(@"Ad failed "
1615
+ @"to present "
1616
+ @"full screen "
1617
+ @"content "
1618
+ @"with error "
1619
+ @"App Open Ad "
1620
+ @"%@.",
1621
+ [error localizedDescription]); */
1622
+ } else if (adFormat == 2) {
1623
+ [self fireEvent:@""
1624
+ event:@"on."
1625
+ @"inte"
1626
+ @"rsti"
1627
+ @"tial"
1628
+ @".fai"
1629
+ @"led."
1630
+ @"load"
1631
+ withData:nil];
1632
+ /* NSLog(@"Ad failed "
1633
+ @"to present "
1634
+ @"full screen "
1635
+ @"content "
1636
+ @"with error "
1637
+ @"interstitial"
1638
+ @" %@.",
1639
+ [error localizedDescription]); */
1640
+ } else if (adFormat == 3) {
1641
+ [self fireEvent:@""
1642
+ event:@"on."
1643
+ @"rewa"
1644
+ @"rded"
1645
+ @".fai"
1646
+ @"led."
1647
+ @"load"
1648
+ withData:nil];
1649
+ /* NSLog(@"Ad failed "
1650
+ @"to present "
1651
+ @"full screen "
1652
+ @"content "
1653
+ @"with error "
1654
+ @"rewarded "
1655
+ @"%@.",
1656
+ [error localizedDescription]); */
1657
+ } else if (adFormat == 4) {
1658
+ [self fireEvent:@""
1659
+ event:@"on."
1660
+ @"rewa"
1661
+ @"rded"
1662
+ @"Int."
1663
+ @"fail"
1664
+ @"ed."
1665
+ @"load"
1666
+ withData:nil];
1667
+ /* NSLog(@"Ad failed "
1668
+ @"to present "
1669
+ @"full screen "
1670
+ @"content "
1671
+ @"with error "
1672
+ @"interstitial"
1673
+ @" "
1674
+ @"rewarded "
1675
+ @"%@.",
1676
+ [error localizedDescription]); */
1677
+ }
1678
+ }
1679
+
1680
+ - (void)adDidDismissFullScreenContent:(id)ad {
1681
+ if (adFormat == 1) {
1682
+ [self fireEvent:@""
1683
+ event:@"on."
1684
+ @"appO"
1685
+ @"penA"
1686
+ @"d."
1687
+ @"dism"
1688
+ @"isse"
1689
+ @"d"
1690
+ withData:nil];
1691
+ /* NSLog(@"Ad did "
1692
+ @"dismiss "
1693
+ @"full screen "
1694
+ @"content App "
1695
+ @"Open Ad."); */
1696
+ } else if (adFormat == 2) {
1697
+ [self fireEvent:@""
1698
+ event:@"on."
1699
+ @"inte"
1700
+ @"rsti"
1701
+ @"tial"
1702
+ @".dis"
1703
+ @"miss"
1704
+ @"ed"
1705
+ withData:nil];
1706
+ /* NSLog(@"Ad did "
1707
+ @"dismiss "
1708
+ @"full screen "
1709
+ @"content "
1710
+ @"interstitial"
1711
+ @"."); */
1712
+ } else if (adFormat == 3) {
1713
+ [self fireEvent:@""
1714
+ event:@"on."
1715
+ @"rewa"
1716
+ @"rded"
1717
+ @".dis"
1718
+ @"miss"
1719
+ @"ed"
1720
+ withData:nil];
1721
+ if (isAdSkip != 2) {
1722
+ [self fireEvent:@""
1723
+ event:@"on"
1724
+ @".r"
1725
+ @"ew"
1726
+ @"ar"
1727
+ @"de"
1728
+ @"d."
1729
+ @"ad"
1730
+ @".s"
1731
+ @"ki"
1732
+ @"p"
1733
+ withData:nil];
1734
+ }
1735
+ /* NSLog(@"Ad did "
1736
+ @"dismiss "
1737
+ @"full screen "
1738
+ @"content "
1739
+ @"rewarded."); */
1740
+ } else if (adFormat == 4) {
1741
+ if (isAdSkip != 2) {
1742
+ [self fireEvent:@""
1743
+ event:@"on"
1744
+ @".r"
1745
+ @"ew"
1746
+ @"ar"
1747
+ @"de"
1748
+ @"dI"
1749
+ @"nt"
1750
+ @".a"
1751
+ @"d."
1752
+ @"sk"
1753
+ @"ip"
1754
+ withData:nil];
1755
+ }
1756
+ [self fireEvent:@""
1757
+ event:@"on."
1758
+ @"rewa"
1759
+ @"rded"
1760
+ @"Int."
1761
+ @"dism"
1762
+ @"isse"
1763
+ @"d"
1764
+ withData:nil];
1765
+ /* NSLog(@"Ad did "
1766
+ @"dismiss "
1767
+ @"full screen "
1768
+ @"content "
1769
+ @"interstitial"
1770
+ @" rewarded."); */
1771
+ }
1772
+ }
515
1773
  #pragma mark Cleanup
516
1774
  - (void)dealloc {
517
- self.appOpenAd = nil;
518
- self.bannerView = nil;
519
- self.interstitial = nil;
520
- self.rewardedAd = nil;
521
- self.rewardedInterstitialAd = nil;
1775
+ self.appOpenAd = nil;
1776
+ self.bannerView = nil;
1777
+ self.interstitial = nil;
1778
+ self.rewardedAd = nil;
1779
+ self.rewardedInterstitialAd = nil;
1780
+ [[NSNotificationCenter defaultCenter]
1781
+ removeObserver:self
1782
+ name:UIDeviceOrientationDidChangeNotification
1783
+ object:nil];
522
1784
  }
523
1785
  @end