emi-indo-cordova-plugin-admob 1.4.8 → 1.5.1

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.
@@ -4,2641 +4,1727 @@
4
4
  #import <Cordova/CDVPlugin.h>
5
5
  #import <Foundation/Foundation.h>
6
6
  #import <UserMessagingPlatform/UserMessagingPlatform.h>
7
- @implementation
8
- emiAdmobPlugin
7
+ @implementation emiAdmobPlugin
9
8
  @synthesize appOpenAd;
10
- @synthesize
11
- bannerView;
12
- @synthesize
13
- interstitial;
14
- @synthesize
15
- rewardedInterstitialAd;
16
- @synthesize
17
- rewardedAd;
9
+ @synthesize bannerView;
10
+ @synthesize interstitial;
11
+ @synthesize rewardedInterstitialAd;
12
+ @synthesize rewardedAd;
18
13
  @synthesize command;
19
- @synthesize
20
- responseInfo;
21
- @synthesize
22
- isPrivacyOptionsRequired;
14
+ @synthesize responseInfo;
15
+ @synthesize isPrivacyOptionsRequired;
23
16
  int idfaStatus = 0;
24
- int fromStatus = 0;
25
- int Consent_Status
26
- = 0;
17
+ int fromStatus = 0; // Deprecated
18
+ int Consent_Status = 0;
27
19
  int adFormat = 0;
28
- int adWidth = 320;
20
+ int adWidth = 320; // Deprecated
29
21
  BOOL auto_Show = NO;
30
- NSString *Npa = @"1";
31
- NSString *Position
32
- = @"bottom";
33
- BOOL EnableCollapsible
34
- = NO;
35
- BOOL ResponseInfo
36
- = NO;
22
+ // NSString *Npa = @"1"; // Deprecated
23
+ NSString *Position = @"bottom";
24
+ NSString *bannerSaveAdUnitId = @""; // autoResize dependency = true
25
+
26
+ BOOL enableCollapsible = NO;
27
+ BOOL isAutoResize = NO;
28
+
37
29
  int isAdSkip = 0;
38
30
  BOOL isIAB = NO;
39
- BOOL UnderAgeOfConsent
40
- = NO;
41
- BOOL isPrivacyOptions
42
- = NO;
43
- BOOL isDebugGeography
44
- = NO;
45
- - (void)initialize:
46
- (CDVInvokedUrlCommand
47
- *)command
48
- {
31
+ BOOL UnderAgeOfConsent = NO;
32
+ BOOL isPrivacyOptions = NO;
33
+ BOOL isDebugGeography = NO;
34
+ BOOL ResponseInfo = NO;
35
+ BOOL isUsingAdManagerRequest = YES;
49
36
 
50
- GADMobileAds *ads =
51
- [GADMobileAds
52
- sharedInstance];
53
- [ads startWithCompletionHandler:^(
54
- GADInitializationStatus
55
- *status) {
56
- NSDictionary *
57
- adapterStatuses
58
- = [status
59
- adapterStatusesByClassName];
60
- for (
61
- NSString *adapter in
62
- adapterStatuses)
63
- {
64
- GADAdapterStatus
65
- *adapterStatus
66
- = adapterStatuses
67
- [adapter];
68
- NSLog (
69
- @"Adapter "
70
- @"Name: %@, "
71
- @"Descriptio"
72
- @"n: %@, "
73
- @"Latency: "
74
- @"%f",
75
- adapter,
76
- adapterStatus
77
- .description,
78
- adapterStatus
79
- .latency);
80
- }
81
- [self
82
- fireEvent:@""
83
- event:
84
- @"on."
85
- @"sdkI"
86
- @"niti"
87
- @"aliz"
88
- @"atio"
89
- @"n"
90
- withData:nil];
91
- }];
37
+ - (BOOL)canRequestAds {
38
+ return UMPConsentInformation.sharedInstance.canRequestAds;
92
39
  }
93
- - (void)requestIDFA:
94
- (CDVInvokedUrlCommand
95
- *)command
96
- {
97
- CDVPluginResult
98
- *pluginResult;
99
- NSString *callbackId
100
- = command
101
- .callbackId;
102
- if (@available (
103
- iOS 14, *))
104
- {
105
- dispatch_async (dispatch_get_main_queue (), ^{
106
- [ATTrackingManager
107
- requestTrackingAuthorizationWithCompletionHandler:^(
108
- ATTrackingManagerAuthorizationStatus
109
- status) {
110
- if (status
111
- == ATTrackingManagerAuthorizationStatusDenied)
112
- {
113
- idfaStatus
114
- = ATTrackingManagerAuthorizationStatusDenied;
115
- }
116
- else if (
117
- status
118
- == ATTrackingManagerAuthorizationStatusAuthorized)
119
- {
120
- idfaStatus
121
- = ATTrackingManagerAuthorizationStatusAuthorized;
122
- }
123
- else if (
124
- status
125
- == ATTrackingManagerAuthorizationStatusRestricted)
126
- {
127
- idfaStatus
128
- = ATTrackingManagerAuthorizationStatusRestricted;
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 = [[options valueForKey:@"isUsingAdManagerRequest"] boolValue];
55
+ BOOL responseInfo = [[options valueForKey:@"isResponseInfo"] boolValue];
56
+ BOOL setDebugGeography = [[options valueForKey:@"isConsentDebug"] boolValue];
57
+
58
+ [self setUsingAdManagerRequest:setAdRequest];
59
+ [self ResponseInfo:responseInfo];
60
+ [self isDebugGeography:setDebugGeography];
61
+
62
+ __block CDVPluginResult *pluginResult;
63
+ NSString *callbackId = command.callbackId;
64
+ NSString *deviceId = [self __getAdMobDeviceId];
65
+ UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
66
+
67
+ if (isDebugGeography) {
68
+ UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
69
+ parameters.debugSettings = debugSettings;
70
+ debugSettings.geography = UMPDebugGeographyEEA;
71
+ debugSettings.testDeviceIdentifiers = @[ deviceId ];
72
+ }
73
+
74
+ parameters.tagForUnderAgeOfConsent = UnderAgeOfConsent;
75
+
76
+ dispatch_async(dispatch_get_main_queue(), ^{
77
+ // Request consent info update
78
+ [UMPConsentInformation.sharedInstance
79
+ requestConsentInfoUpdateWithParameters:parameters
80
+ completionHandler:^(NSError *_Nullable requestConsentError) {
81
+ if (requestConsentError) {
82
+ // NSLog(@"Request consent error: %@", requestConsentError.localizedDescription);
83
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:requestConsentError.description];
84
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
85
+ return;
129
86
  }
130
- else if (
131
- status
132
- == ATTrackingManagerAuthorizationStatusNotDetermined)
133
- {
134
- idfaStatus
135
- = ATTrackingManagerAuthorizationStatusNotDetermined;
87
+
88
+ // Check the consent status after update
89
+ UMPConsentStatus status = UMPConsentInformation.sharedInstance.consentStatus;
90
+ // NSLog(@"Consent status: %ld", (long)status);
91
+
92
+ // Handle consent status
93
+ if (status == UMPConsentStatusRequired) {
94
+ // If consent is required, load and display consent form
95
+ [UMPConsentForm loadWithCompletionHandler:^(UMPConsentForm *form, NSError *loadError) {
96
+ if (loadError) {
97
+ // NSLog(@"Load consent form error: %@", loadError.localizedDescription);
98
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:loadError.description];
99
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
100
+ } else {
101
+ // Present the consent form to the user
102
+ [form presentFromViewController:[UIApplication sharedApplication].delegate.window.rootViewController
103
+ completionHandler:^(NSError *_Nullable dismissError) {
104
+ if (dismissError) {
105
+ // NSLog(@"Dismiss consent form error: %@", dismissError.localizedDescription);
106
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:dismissError.description];
107
+ } else {
108
+ // NSLog(@"Consent form successfully presented.");
109
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Consent form displayed successfully."];
110
+ }
111
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
112
+ }];
113
+ }
114
+
115
+
116
+ if (UMPConsentInformation.sharedInstance.canRequestAds) {
117
+ [self startGoogleMobileAdsSDK];
118
+ }
119
+
120
+
121
+ }];
122
+ } else if (status == UMPConsentStatusNotRequired || status == UMPConsentStatusObtained) {
123
+ // If consent is not required or already obtained, start the ads SDK
124
+ if (UMPConsentInformation.sharedInstance.canRequestAds) {
125
+ [self startGoogleMobileAdsSDK];
126
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Ads SDK started."];
127
+ } else {
128
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Cannot request ads, consent is required."];
129
+ }
130
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
131
+ } else {
132
+ // NSLog(@"Consent status unknown or error.");
133
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Consent status unknown."];
134
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
136
135
  }
137
- }];
138
- });
139
- [self
140
- fireEvent:@""
141
- event:
142
- @"on."
143
- @"getI"
144
- @"DFA."
145
- @"stat"
146
- @"us"
147
- withData:nil];
148
- pluginResult = [CDVPluginResult
149
- resultWithStatus:
150
- CDVCommandStatus_OK
151
- messageAsInt:
152
- idfaStatus];
153
- }
154
- else
155
- {
156
- [self
157
- fireEvent:@""
158
- event:
159
- @"on."
160
- @"getI"
161
- @"DFA."
162
- @"erro"
163
- @"r"
164
- withData:nil];
165
- pluginResult = [CDVPluginResult
166
- resultWithStatus:
167
- CDVCommandStatus_ERROR];
168
- }
169
- [self.commandDelegate
170
- sendPluginResult:
171
- pluginResult
172
- callbackId:
173
- callbackId];
136
+ }];
137
+ });
174
138
  }
175
139
 
176
- - (void)
177
- getConsentRequest:
178
- (CDVInvokedUrlCommand
179
- *)command
180
- {
181
- __block
182
- CDVPluginResult *
183
- pluginResult;
184
- NSString *callbackId
185
- = command
186
- .callbackId;
187
- NSString *deviceId = [self
188
- __getAdMobDeviceId];
189
- UMPRequestParameters
190
- *parameters
191
- = [[UMPRequestParameters
192
- alloc] init];
193
-
194
- if (isDebugGeography
195
- == YES)
196
- {
197
- UMPDebugSettings
198
- *debugSettings
199
- = [[UMPDebugSettings
200
- alloc]
201
- init];
202
- parameters
203
- .debugSettings
204
- = debugSettings;
205
- debugSettings
206
- .geography
207
- = UMPDebugGeographyEEA;
208
- debugSettings
209
- .testDeviceIdentifiers
210
- = @[
211
- deviceId
212
- ];
213
- }
214
- parameters
215
- .tagForUnderAgeOfConsent
216
- = UnderAgeOfConsent;
217
- // NSLog(@"tag For
218
- // Under Age Of
219
- // Consent %s",
220
- // UnderAgeOfConsent
221
- // ? "true" :
222
- // "false");
223
- dispatch_async (dispatch_get_main_queue (),
224
- ^{
225
- [UMPConsentInformation
226
- .sharedInstance
227
- requestConsentInfoUpdateWithParameters:
228
- parameters
229
- completionHandler:^(
230
- NSError
231
- *_Nullable requestConsentError) {
232
- if (requestConsentError)
233
- {
234
- NSLog (
235
- @"request Consent Error: %@",
236
- requestConsentError
237
- .localizedDescription);
238
-
239
- pluginResult = [CDVPluginResult
240
- resultWithStatus:
241
- CDVCommandStatus_ERROR
242
- messageAsString:
243
- requestConsentError
244
- .description];
245
-
246
- return;
247
- }
248
- [self
249
- readStatus:
250
- command];
251
- [UMPConsentForm loadWithCompletionHandler:^(
252
- UMPConsentForm
253
- *form,
254
- NSError
255
- *loadError) {
256
- if (loadError)
257
- {
258
- pluginResult = [CDVPluginResult
259
- resultWithStatus:
260
- CDVCommandStatus_ERROR
261
- messageAsString:
262
- loadError
263
- .description];
264
- NSLog (
265
- @"load Error: %@",
266
- loadError
267
- .localizedDescription);
268
- }
269
- else
270
- {
271
- [form
272
- presentFromViewController:
273
- [UIApplication
274
- sharedApplication]
275
- .delegate
276
- .window
277
- .rootViewController
278
- completionHandler:
279
- ^(NSError
280
- *_Nullable dismissError) {
281
- if (dismissError)
282
- {
283
- NSLog (
284
- @"dismiss Error: %@",
285
- dismissError
286
- .localizedDescription);
287
- pluginResult = [CDVPluginResult
288
- resultWithStatus:
289
- CDVCommandStatus_ERROR
290
- messageAsString:
291
- dismissError
292
- .description];
293
- }
294
- else
295
- {
296
- NSLog (
297
- @"UMP ConsentInformation: %@",
298
- UMPConsentInformation
299
- .description);
300
- pluginResult = [CDVPluginResult
301
- resultWithStatus:
302
- CDVCommandStatus_ERROR
303
- messageAsString:
304
- UMPConsentInformation
305
- .description];
140
+
141
+
142
+ - (void)requestIDFA:(CDVInvokedUrlCommand *)command {
143
+ CDVPluginResult *pluginResult;
144
+ NSString *callbackId = command.callbackId;
145
+ if (@available(iOS 14, *)) {
146
+ dispatch_async(dispatch_get_main_queue(), ^{
147
+ [ATTrackingManager
148
+ requestTrackingAuthorizationWithCompletionHandler:^(
149
+ ATTrackingManagerAuthorizationStatus status) {
150
+ if (status == ATTrackingManagerAuthorizationStatusDenied) {
151
+ idfaStatus = ATTrackingManagerAuthorizationStatusDenied;
152
+ } else if (status ==
153
+ ATTrackingManagerAuthorizationStatusAuthorized) {
154
+ idfaStatus = ATTrackingManagerAuthorizationStatusAuthorized;
155
+ } else if (status ==
156
+ ATTrackingManagerAuthorizationStatusRestricted) {
157
+ idfaStatus = ATTrackingManagerAuthorizationStatusRestricted;
158
+ } else if (status ==
159
+ ATTrackingManagerAuthorizationStatusNotDetermined) {
160
+ idfaStatus =
161
+ ATTrackingManagerAuthorizationStatusNotDetermined;
306
162
  }
307
- }];
308
- }
309
- }];
310
-
311
- [self
312
- fireEvent:
313
- @""
314
- event:
315
- @"on.get.from.status"
316
- withData:
317
- nil];
318
- }];
319
-
320
- [self.commandDelegate
321
- sendPluginResult:
322
- pluginResult
323
- callbackId:
324
- callbackId];
325
- });
163
+ }];
164
+ });
165
+ [self fireEvent:@""
166
+ event:@"on."
167
+ @"getI"
168
+ @"DFA."
169
+ @"stat"
170
+ @"us"
171
+ withData:nil];
172
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
173
+ messageAsInt:idfaStatus];
174
+ } else {
175
+ [self fireEvent:@""
176
+ event:@"on."
177
+ @"getI"
178
+ @"DFA."
179
+ @"erro"
180
+ @"r"
181
+ withData:nil];
182
+ pluginResult =
183
+ [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
184
+ }
185
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
326
186
  }
327
187
 
328
- - (void)
329
- showPrivacyOptionsForm:
330
- (CDVInvokedUrlCommand
331
- *)command
332
- {
333
- NSString *deviceId = [self
334
- __getAdMobDeviceId];
335
- UMPRequestParameters
336
- *parameters
337
- = [[UMPRequestParameters
338
- alloc] init];
339
- if (isDebugGeography
340
- == YES)
341
- {
342
- UMPDebugSettings
343
- *debugSettings
344
- = [[UMPDebugSettings
345
- alloc]
346
- init];
347
- parameters
348
- .debugSettings
349
- = debugSettings;
350
- debugSettings
351
- .geography
352
- = UMPDebugGeographyEEA;
353
- debugSettings
354
- .testDeviceIdentifiers
355
- = @[
356
- deviceId
357
- ];
358
- }
359
- parameters
360
- .tagForUnderAgeOfConsent
361
- = UnderAgeOfConsent;
362
- dispatch_async (dispatch_get_main_queue (),
363
- ^{
364
- [UMPConsentInformation
365
- .sharedInstance
366
- requestConsentInfoUpdateWithParameters:
367
- parameters
368
- completionHandler:
369
- ^(NSError
370
- *_Nullable requestConsentError) {
371
- [UMPConsentForm
372
- loadAndPresentIfRequiredFromViewController:
373
- self.viewController
374
- completionHandler:^(
375
- NSError
376
- *loadAndPresentError) {
377
- CDVPluginResult
378
- *pluginResult
379
- = [CDVPluginResult
380
- resultWithStatus:
381
- CDVCommandStatus_ERROR
382
- messageAsString:
383
- loadAndPresentError
384
- .description];
385
- [self.commandDelegate
386
- sendPluginResult:
387
- pluginResult
388
- callbackId:
389
- command
390
- .callbackId];
391
- }];
392
-
393
- [self
394
- isPrivacyOptionsRequired];
395
- isPrivacyOptions
396
- = YES;
397
- [self
398
- privacyOptionsFormShow:
399
- command];
400
- }];
401
- });
188
+ - (void)getConsentRequest:(CDVInvokedUrlCommand *)command {
189
+
402
190
  }
403
191
 
404
- - (void)
405
- privacyOptionsFormShow:
406
- (CDVInvokedUrlCommand
407
- *)command
408
- {
409
192
 
410
- [self.commandDelegate runInBackground:
411
- ^{
412
- if (isPrivacyOptions
413
- == YES)
414
- {
415
- dispatch_async (dispatch_get_main_queue (),
416
- ^{
417
- [UMPConsentForm presentPrivacyOptionsFormFromViewController:
418
- self.viewController
419
- completionHandler:
420
- ^(NSError
421
- *_Nullable formError) {
422
- if (formError)
423
- {
424
- // Handle the error.
425
- CDVPluginResult
426
- *pluginResult
427
- = [CDVPluginResult
428
- resultWithStatus:
429
- CDVCommandStatus_ERROR
430
- messageAsString:
431
- formError
432
- .description];
433
- [self.commandDelegate
434
- sendPluginResult:
435
- pluginResult
436
- callbackId:
437
- command
438
- .callbackId];
439
- }
440
- }];
441
- });
442
- }
443
- }];
193
+
194
+
195
+
196
+
197
+
198
+
199
+ - (void)startGoogleMobileAdsSDK {
200
+ static dispatch_once_t onceToken;
201
+ dispatch_once(&onceToken, ^{
202
+ // Initialize the Google Mobile Ads SDK.
203
+ GADMobileAds *ads = [GADMobileAds sharedInstance];
204
+ [ads startWithCompletionHandler:^(GADInitializationStatus *status) {
205
+
206
+ NSDictionary *adapterStatuses = [status adapterStatusesByClassName];
207
+ NSMutableArray *adaptersArray = [NSMutableArray array];
208
+
209
+ for (NSString *adapter in adapterStatuses) {
210
+ GADAdapterStatus *adapterStatus = adapterStatuses[adapter];
211
+ NSLog(@"Adapter Name: %@, Description: %@, Latency: %f", adapter, adapterStatus.description, adapterStatus.latency);
212
+
213
+ NSDictionary *adapterInfo = @{
214
+ @"name": adapter
215
+ };
216
+
217
+ [adaptersArray addObject:adapterInfo];
218
+ }
219
+
220
+ NSString *sdkVersion = GADGetStringFromVersionNumber(GADMobileAds.sharedInstance.versionNumber);
221
+ int Consent_Status = (int)UMPConsentInformation.sharedInstance.consentStatus;
222
+
223
+ NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
224
+ NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
225
+ NSNumber *CmpSdkID = [prefs valueForKey:@"IABTCF_CmpSdkID"];
226
+ NSString *gdprApplies = [prefs stringForKey:@"IABTCF_gdprApplies"];
227
+ NSString *PurposeConsents = [prefs stringForKey:@"IABTCF_PurposeConsents"];
228
+ NSString *TCString = [prefs stringForKey:@"IABTCF_TCString"];
229
+ NSString *additionalConsent = [prefs stringForKey:@"IABTCF_AddtlConsent"];
230
+
231
+ result[@"version"] = sdkVersion;
232
+ result[@"consentStatus"] = @(Consent_Status);
233
+ result[@"adapter"] = adaptersArray;
234
+ result[@"CmpSdkID"] = CmpSdkID;
235
+ result[@"gdprApplies"] = gdprApplies;
236
+ result[@"PurposeConsents"] = PurposeConsents;
237
+ result[@"TCString"] = TCString;
238
+ result[@"additionalConsent"] = additionalConsent;
239
+
240
+ // NSLog(@"Result dictionary: %@", result);consentStatus
241
+
242
+ NSError *error;
243
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:result options:0 error:&error];
244
+
245
+ if (!jsonData) {
246
+ NSLog(@"Error converting result to JSON: %@", error.localizedDescription);
247
+ } else {
248
+ NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
249
+
250
+ // NSLog(@"JSON String: %@", jsonString);
251
+
252
+ [self fireEvent:@"" event:@"on.sdkInitialization" withData:jsonString];
253
+ }
254
+
255
+ [prefs synchronize];
256
+ }];
257
+ });
444
258
  }
445
259
 
446
- - (void)readStatus:
447
- (CDVInvokedUrlCommand
448
- *)command
449
- {
450
- [self.commandDelegate runInBackground:^{
451
- Consent_Status
452
- = (int)UMPConsentInformation
453
- .sharedInstance
454
- .consentStatus;
455
-
456
- if (Consent_Status
457
- == UMPConsentStatusUnknown)
458
- {
459
260
 
460
- Consent_Status
461
- = UMPConsentStatusUnknown;
462
- }
463
- else if (
464
- Consent_Status
465
- == UMPConsentStatusRequired)
466
- {
467
261
 
468
- Consent_Status
469
- = UMPConsentStatusRequired;
470
- }
471
- else if (
472
- Consent_Status
473
- == UMPConsentStatusNotRequired)
474
- {
475
262
 
476
- Consent_Status
477
- = UMPConsentStatusNotRequired;
263
+
264
+
265
+ - (void)forceDisplayPrivacyForm:(CDVInvokedUrlCommand *)command {
266
+ NSString *deviceId = [self __getAdMobDeviceId];
267
+ UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
268
+
269
+ if (isDebugGeography) {
270
+ UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
271
+ debugSettings.geography = UMPDebugGeographyEEA;
272
+ debugSettings.testDeviceIdentifiers = @[ deviceId ];
273
+ parameters.debugSettings = debugSettings;
478
274
  }
479
- else if (
480
- Consent_Status
481
- == UMPConsentStatusObtained)
482
- {
275
+
276
+ parameters.tagForUnderAgeOfConsent = UnderAgeOfConsent;
277
+
278
+ // [UMPConsentInformation.sharedInstance reset];
279
+
280
+ dispatch_async(dispatch_get_main_queue(), ^{
281
+ [UMPConsentInformation.sharedInstance
282
+ requestConsentInfoUpdateWithParameters:parameters
283
+ completionHandler:^(NSError *_Nullable requestConsentError) {
284
+ if (requestConsentError != nil) {
285
+ // NSLog(@"Errors in updating consent information: %@", requestConsentError);
286
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:requestConsentError.description];
287
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
288
+ return;
289
+ }
290
+
291
+ // NSLog(@"Successful update of consent info. Continue to load and present consent form.");
292
+
293
+ [UMPConsentForm loadAndPresentIfRequiredFromViewController:self.viewController
294
+ completionHandler:^(NSError *loadAndPresentError) {
295
+ if (loadAndPresentError != nil) {
296
+ // NSLog(@"Error loading and presenting consent form: %@", loadAndPresentError);
297
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:loadAndPresentError.description];
298
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
299
+ } else {
300
+ // NSLog(@"Consent form successfully loaded");
301
+ [UMPConsentForm presentPrivacyOptionsFormFromViewController:self.viewController completionHandler:^(NSError * _Nullable formError) {
302
+ if (formError) {
303
+ // NSLog(@"Error when displaying the form: %@", formError);
304
+ } else {
305
+ // NSLog(@"The privacy options form is successfully displayed.");
306
+ }
307
+ }];
308
+ }
309
+ }];
310
+ }];
311
+ });
312
+ }
483
313
 
484
- Consent_Status
485
- = UMPConsentStatusObtained;
314
+
315
+
316
+
317
+
318
+ - (void)showPrivacyOptionsForm:(CDVInvokedUrlCommand *)command {
319
+ NSString *deviceId = [self __getAdMobDeviceId];
320
+ UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
321
+
322
+ if (isDebugGeography) {
323
+ UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
324
+ parameters.debugSettings = debugSettings;
325
+ debugSettings.geography = UMPDebugGeographyEEA;
326
+ debugSettings.testDeviceIdentifiers = @[ deviceId ];
327
+
328
+ // NSLog(@"[showPrivacyOptionsForm] Using EEA debug geography for consent.");
486
329
  }
330
+
331
+ parameters.tagForUnderAgeOfConsent = UnderAgeOfConsent;
332
+
333
+ dispatch_async(dispatch_get_main_queue(), ^{
334
+ [UMPConsentInformation.sharedInstance
335
+ requestConsentInfoUpdateWithParameters:parameters
336
+ completionHandler:^(NSError *_Nullable requestConsentError) {
337
+ if (requestConsentError != nil) {
338
+ // NSLog(@"[showPrivacyOptionsForm] Error in updating consent info: %@", requestConsentError);
339
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:requestConsentError.description];
340
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
341
+ return;
342
+ }
343
+
344
+ // NSLog(@"[showPrivacyOptionsForm] Successful update of consent info. Continue to load and present consent form.");
345
+
346
+ [UMPConsentForm loadAndPresentIfRequiredFromViewController:self.viewController
347
+ completionHandler:^(NSError *loadAndPresentError) {
348
+ if (loadAndPresentError) {
349
+ // NSLog(@"[showPrivacyOptionsForm] Error loading and presenting consent form: %@", loadAndPresentError);
350
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:loadAndPresentError.description];
351
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
352
+ } else {
353
+ /// NSLog(@"[showPrivacyOptionsForm] Consent form successfully displayed.");
354
+ }
355
+ }];
356
+
357
+
358
+ if ([self isPrivacyOptionsRequired]) {
359
+ // NSLog(@"[isPrivacyOptionsRequired] Privacy options required.");
360
+ [self privacyOptionsFormShow:command];
361
+ } else {
362
+ // NSLog(@"[isPrivacyOptionsRequired] Privacy option form not required.");
363
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"The privacy option form is not required."];
364
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
365
+ }
366
+ }];
367
+ });
368
+ }
487
369
 
488
- NSLog (
489
- @"The Consent "
490
- @"Status %i",
491
- Consent_Status);
492
- CDVPluginResult
493
- *pluginResult
494
- = [CDVPluginResult
495
- resultWithStatus:
496
- CDVCommandStatus_OK
497
- messageAsInt:
498
- Consent_Status];
499
- [self.commandDelegate
500
- sendPluginResult:
501
- pluginResult
502
- callbackId:
503
- command
504
- .callbackId];
505
- }];
370
+
371
+ - (void)privacyOptionsFormShow:(CDVInvokedUrlCommand *)command {
372
+ [self.commandDelegate runInBackground:^{
373
+ dispatch_async(dispatch_get_main_queue(), ^{
374
+ [UMPConsentForm presentPrivacyOptionsFormFromViewController:self.viewController
375
+ completionHandler:^(NSError *_Nullable formError) {
376
+ if (formError) {
377
+ // NSLog(@"[privacyOptionsFormShow] Error displaying the privacy options form: %@", formError);
378
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:formError.description];
379
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
380
+ } else {
381
+ // NSLog(@"[privacyOptionsFormShow] The privacy options form is successfully displayed.");
382
+ }
383
+ }];
384
+ });
385
+ }];
506
386
  }
507
387
 
508
- - (BOOL)
509
- isPrivacyOptionsRequired
510
- {
511
- return UMPConsentInformation
512
- .sharedInstance
513
- .privacyOptionsRequirementStatus
514
- == UMPPrivacyOptionsRequirementStatusRequired;
388
+ // Cek apakah opsi privasi diperlukan
389
+ - (BOOL)isPrivacyOptionsRequired {
390
+ UMPPrivacyOptionsRequirementStatus status = UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus;
391
+ // NSLog(@"[isPrivacyOptionsRequired] Privacy option status: %ld", (long)status);
392
+ return status == UMPPrivacyOptionsRequirementStatusRequired;
515
393
  }
516
394
 
517
- - (void)
518
- pluginInitialize
519
- {
520
- isIAB = YES;
521
- NSMutableDictionary
522
- *result
523
- = [[NSMutableDictionary
524
- alloc] init];
525
- NSUserDefaults *prefs
526
- = [NSUserDefaults
527
- standardUserDefaults];
528
- NSNumber *CmpSdkID =
529
- [prefs
530
- valueForKey:
531
- @"IABTCF"
532
- @"_CmpSd"
533
- @"kID"];
534
- NSString *gdprApplies
535
- = [prefs
536
- stringForKey:
537
- @"IABTCF"
538
- @"_gdprA"
539
- @"pplie"
540
- @"s"];
541
- NSString
542
- *PurposeConsents
543
- = [prefs
544
- stringForKey:
545
- @"IABTCF"
546
- @"_Purpo"
547
- @"seCons"
548
- @"ents"];
549
- NSString *TCString =
550
- [prefs
551
- stringForKey:
552
- @"IABTCF"
553
- @"_TCStr"
554
- @"ing"];
555
- result[@"IABTCF_"
556
- @"CmpSdkID"]
557
- = CmpSdkID;
558
- result
559
- [@"IABTCF_"
560
- @"gdprApplies"]
561
- = gdprApplies;
562
- result[@"IABTCF_"
563
- @"PurposeCons"
564
- @"ents"]
565
- = PurposeConsents;
566
- result[@"IABTCF_"
567
- @"TCString"]
568
- = TCString;
569
- // NSLog(@"%@",
570
- // [[NSUserDefaults
571
- // standardUserDefaults]
572
- // dictionaryRepresentation]);
573
- [prefs synchronize];
395
+
396
+ - (void)readStatus:(CDVInvokedUrlCommand *)command {
397
+ [self.commandDelegate runInBackground:^{
398
+ Consent_Status = (int)UMPConsentInformation.sharedInstance.consentStatus;
399
+
400
+ if (Consent_Status == UMPConsentStatusUnknown) {
401
+
402
+ Consent_Status = UMPConsentStatusUnknown;
403
+ } else if (Consent_Status == UMPConsentStatusRequired) {
404
+
405
+ Consent_Status = UMPConsentStatusRequired;
406
+ } else if (Consent_Status == UMPConsentStatusNotRequired) {
407
+
408
+ Consent_Status = UMPConsentStatusNotRequired;
409
+ } else if (Consent_Status == UMPConsentStatusObtained) {
410
+
411
+ Consent_Status = UMPConsentStatusObtained;
412
+ }
413
+
414
+ NSLog(@"The Consent " @"Status %i",
415
+ Consent_Status);
416
+ CDVPluginResult *pluginResult =
417
+ [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
418
+ messageAsInt:Consent_Status];
419
+ [self.commandDelegate sendPluginResult:pluginResult
420
+ callbackId:command.callbackId];
421
+ }];
574
422
  }
575
- - (void)getIabTfc:
576
- (CDVInvokedUrlCommand
577
- *)command
578
- {
579
- CDVPluginResult
580
- *pluginResult;
581
- NSString *callbackId
582
- = command
583
- .callbackId;
584
- if (isIAB == 1)
585
- {
586
- NSMutableDictionary
587
- *result
588
- = [[NSMutableDictionary
589
- alloc]
590
- init];
591
- NSUserDefaults
592
- *prefs
593
- = [NSUserDefaults
594
- standardUserDefaults];
595
- NSNumber *CmpSdkID
596
- = [prefs
597
- valueForKey:
598
- @"IABT"
599
- @"CF_"
600
- @"CmpS"
601
- @"dkI"
602
- @"D"];
603
- NSString
604
- *gdprApplies
605
- = [prefs
606
- stringForKey:
607
- @"IABT"
608
- @"CF_"
609
- @"gdpr"
610
- @"Appl"
611
- @"ie"
612
- @"s"];
613
- NSString *
614
- PurposeConsents
615
- = [prefs
616
- stringForKey:
617
- @"IABT"
618
- @"CF_"
619
- @"Purp"
620
- @"oseC"
621
- @"onse"
622
- @"nt"
623
- @"s"];
624
- NSString *TCString
625
- = [prefs
626
- stringForKey:
627
- @"IABT"
628
- @"CF_"
629
- @"TCSt"
630
- @"rin"
631
- @"g"];
632
- result[@"IABTCF_"
633
- @"CmpSdkID"]
634
- = CmpSdkID;
635
- result[@"IABTCF_"
636
- @"gdprAppli"
637
- @"es"]
638
- = gdprApplies;
639
- result[@"IABTCF_"
640
- @"PurposeCo"
641
- @"nsents"]
642
- = PurposeConsents;
643
- result[@"IABTCF_"
644
- @"TCString"]
645
- = TCString;
646
- [[NSUserDefaults
647
- standardUserDefaults]
648
- synchronize];
649
- NSLog (
650
- @"%@",
651
- [[NSUserDefaults
652
- standardUserDefaults]
653
- dictionaryRepresentation]);
654
- pluginResult = [CDVPluginResult
655
- resultWithStatus:
656
- CDVCommandStatus_OK
657
- messageAsDictionary:
658
- result];
659
- [self
660
- fireEvent:@""
661
- event:
662
- @"on."
663
- @"getI"
664
- @"abTf"
665
- @"c"
666
- withData:nil];
667
- }
668
- else
669
- {
670
- pluginResult = [CDVPluginResult
671
- resultWithStatus:
672
- CDVCommandStatus_ERROR];
673
- }
674
- [self.commandDelegate
675
- sendPluginResult:
676
- pluginResult
677
- callbackId:
678
- callbackId];
423
+
424
+
425
+ - (void)getIabTfc:(CDVInvokedUrlCommand *)command {
426
+ CDVPluginResult *pluginResult;
427
+ NSString *callbackId = command.callbackId;
428
+ if (isIAB == 1) {
429
+ NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
430
+ NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
431
+ NSNumber *CmpSdkID = [prefs valueForKey:@"IABT"
432
+ @"CF_"
433
+ @"CmpS"
434
+ @"dkI"
435
+ @"D"];
436
+ NSString *gdprApplies = [prefs stringForKey:@"IABT"
437
+ @"CF_"
438
+ @"gdpr"
439
+ @"Appl"
440
+ @"ie"
441
+ @"s"];
442
+ NSString *PurposeConsents = [prefs stringForKey:@"IABT"
443
+ @"CF_"
444
+ @"Purp"
445
+ @"oseC"
446
+ @"onse"
447
+ @"nt"
448
+ @"s"];
449
+ NSString *TCString = [prefs stringForKey:@"IABT"
450
+ @"CF_"
451
+ @"TCSt"
452
+ @"rin"
453
+ @"g"];
454
+ result[@"IABTCF_"
455
+ @"CmpSdkID"] = CmpSdkID;
456
+ result[@"IABTCF_"
457
+ @"gdprAppli"
458
+ @"es"] = gdprApplies;
459
+ result[@"IABTCF_"
460
+ @"PurposeCo"
461
+ @"nsents"] = PurposeConsents;
462
+ result[@"IABTCF_"
463
+ @"TCString"] = TCString;
464
+ [[NSUserDefaults standardUserDefaults] synchronize];
465
+ NSLog(@"%@",
466
+ [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
467
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
468
+ messageAsDictionary:result];
469
+ [self fireEvent:@""
470
+ event:@"on."
471
+ @"getI"
472
+ @"abTf"
473
+ @"c"
474
+ withData:nil];
475
+ } else {
476
+ pluginResult =
477
+ [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
478
+ }
479
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
679
480
  }
680
- - (void)consentReset:
681
- (CDVInvokedUrlCommand
682
- *)command
683
- {
684
- CDVPluginResult
685
- *pluginResult;
686
- NSString *callbackId
687
- = command
688
- .callbackId;
689
- @try
690
- {
691
- [[UMPConsentInformation
692
- sharedInstance]
693
- reset];
694
- pluginResult = [CDVPluginResult
695
- resultWithStatus:
696
- CDVCommandStatus_OK];
697
- }
698
- @catch (
699
- NSException
700
- *exception)
701
- {
702
- pluginResult = [CDVPluginResult
703
- resultWithStatus:
704
- CDVCommandStatus_ERROR
705
- messageAsString:
706
- exception
707
- .reason];
708
- }
709
- [self.commandDelegate
710
- sendPluginResult:
711
- pluginResult
712
- callbackId:
713
- callbackId];
481
+ - (void)consentReset:(CDVInvokedUrlCommand *)command {
482
+ CDVPluginResult *pluginResult;
483
+ NSString *callbackId = command.callbackId;
484
+ @try {
485
+ [[UMPConsentInformation sharedInstance] reset];
486
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
487
+ } @catch (NSException *exception) {
488
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
489
+ messageAsString:exception.reason];
490
+ }
491
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
714
492
  }
715
- - (void)
716
- setPublisherFirstPartyIDEnabled:
717
- (BOOL)enabled
718
- {
719
- };
720
- - (void)globalSettings:
721
- (CDVInvokedUrlCommand
722
- *)command
723
- {
724
- CDVPluginResult
725
- *pluginResult;
726
- NSString *callbackId
727
- = command
728
- .callbackId;
729
- BOOL setAppMuted =
730
- [[command
731
- argumentAtIndex:
732
- 0]
733
- boolValue];
734
- float setAppVolume =
735
- [[command
736
- argumentAtIndex:
737
- 1]
738
- floatValue];
739
- BOOL
740
- publisherFirstPartyIdEnabled
741
- = [[command
742
- argumentAtIndex:
743
- 3]
744
- boolValue];
745
- NSString *npa =
746
- [command.arguments
747
- objectAtIndex:
748
- 2];
749
- BOOL
750
- enableCollapsible
751
- = [[command
752
- argumentAtIndex:
753
- 3]
754
- boolValue];
755
- BOOL responseInfo =
756
- [[command
757
- argumentAtIndex:
758
- 4]
759
- boolValue];
760
- BOOL
761
- setDebugGeography
762
- = [[command
763
- argumentAtIndex:
764
- 5]
765
- boolValue];
766
- @try
767
- {
768
- GADMobileAds
769
- .sharedInstance
770
- .applicationVolume
771
- = setAppVolume;
772
- GADMobileAds
773
- .sharedInstance
774
- .applicationMuted
775
- = setAppMuted;
776
- [self
777
- setPublisherFirstPartyIDEnabled:
778
- publisherFirstPartyIdEnabled];
779
- Npa = npa;
780
- EnableCollapsible
781
- = enableCollapsible;
782
- ResponseInfo
783
- = responseInfo;
784
- isDebugGeography
785
- = setDebugGeography;
786
- pluginResult = [CDVPluginResult
787
- resultWithStatus:
788
- CDVCommandStatus_OK];
789
- }
790
- @catch (
791
- NSException
792
- *exception)
793
- {
794
- pluginResult = [CDVPluginResult
795
- resultWithStatus:
796
- CDVCommandStatus_ERROR
797
- messageAsString:
798
- exception
799
- .reason];
800
- }
801
- [self.commandDelegate
802
- sendPluginResult:
803
- pluginResult
804
- callbackId:
805
- callbackId];
493
+
494
+
495
+
496
+
497
+
498
+
499
+ - (void)globalSettings:(CDVInvokedUrlCommand *)command {
500
+ CDVPluginResult *pluginResult;
501
+ NSString *callbackId = command.callbackId;
502
+ NSDictionary *options = [command.arguments objectAtIndex:0];
503
+ BOOL setAppMuted = [[options valueForKey:@"setAppMuted"] boolValue];
504
+ BOOL setAppVolume = [[options valueForKey:@"setAppVolume"] boolValue];
505
+ BOOL pubIdEnabled = [[options valueForKey:@"pubIdEnabled"] boolValue];
506
+ @try {
507
+ GADMobileAds.sharedInstance.applicationVolume = setAppVolume;
508
+ GADMobileAds.sharedInstance.applicationMuted = setAppMuted;
509
+ [GADMobileAds.sharedInstance.requestConfiguration setPublisherFirstPartyIDEnabled:pubIdEnabled];
510
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
511
+ } @catch (NSException *exception) {
512
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
513
+ messageAsString:exception.reason];
514
+ }
515
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
806
516
  }
807
- - (void)targeting:
808
- (CDVInvokedUrlCommand
809
- *)command
810
- {
811
- CDVPluginResult
812
- *pluginResult;
813
- NSString *callbackId
814
- = command
815
- .callbackId;
816
- NSNumber *
817
- childDirectedTreatment
818
- = [command
819
- argumentAtIndex:
820
- 0];
821
- NSNumber *
822
- underAgeOfConsent
823
- = [command
824
- argumentAtIndex:
825
- 1];
826
- NSString
827
- *contentRating
828
- = [command
829
- argumentAtIndex:
830
- 2];
831
- @try
832
- {
833
- GADRequestConfiguration
834
- *requestConfiguration
835
- = GADMobileAds
836
- .sharedInstance
837
- .requestConfiguration;
838
- requestConfiguration
839
- .tagForChildDirectedTreatment
840
- = childDirectedTreatment;
841
- requestConfiguration
842
- .tagForUnderAgeOfConsent
843
- = underAgeOfConsent;
844
- requestConfiguration
845
- .maxAdContentRating
846
- = contentRating;
847
- UnderAgeOfConsent
848
- = underAgeOfConsent;
849
- }
850
- @catch (
851
- NSException
852
- *exception)
853
- {
854
- pluginResult = [CDVPluginResult
855
- resultWithStatus:
856
- CDVCommandStatus_ERROR
857
- messageAsString:
858
- exception
859
- .reason];
860
- }
861
- [self.commandDelegate
862
- sendPluginResult:
863
- pluginResult
864
- callbackId:
865
- callbackId];
517
+
518
+
519
+ - (void)targeting:(CDVInvokedUrlCommand *)command {
520
+ CDVPluginResult *pluginResult;
521
+ NSString *callbackId = command.callbackId;
522
+ NSDictionary *options = [command.arguments objectAtIndex:0];
523
+ BOOL childDirectedTreatment = [[options valueForKey:@"childDirectedTreatment"] boolValue];
524
+ BOOL underAgeOfConsent = [[options valueForKey:@"underAgeOfConsent"] boolValue];
525
+ NSString *contentRating = [options valueForKey:@"contentRating"];
526
+ @try {
527
+ GADRequestConfiguration *requestConfiguration = GADMobileAds.sharedInstance.requestConfiguration;
528
+ requestConfiguration.tagForChildDirectedTreatment = @(childDirectedTreatment);
529
+ requestConfiguration.tagForUnderAgeOfConsent = @(underAgeOfConsent);
530
+
531
+ if (contentRating != nil) {
532
+ if ([contentRating isEqualToString:@"G"]) {
533
+ requestConfiguration.maxAdContentRating = GADMaxAdContentRatingGeneral;
534
+ } else if ([contentRating isEqualToString:@"PG"]) {
535
+ requestConfiguration.maxAdContentRating = GADMaxAdContentRatingParentalGuidance;
536
+ } else if ([contentRating isEqualToString:@"T"]) {
537
+ requestConfiguration.maxAdContentRating = GADMaxAdContentRatingTeen;
538
+ } else if ([contentRating isEqualToString:@"MA"]) {
539
+ requestConfiguration.maxAdContentRating = GADMaxAdContentRatingMatureAudience;
540
+ } else {
541
+ // NSLog(@"Unknown content rating: %@", contentRating);
542
+ }
543
+ }
544
+
545
+ UnderAgeOfConsent = underAgeOfConsent;
546
+
547
+ } @catch (NSException *exception) {
548
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
549
+ messageAsString:exception.reason];
550
+ }
551
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
866
552
  }
867
- - (GADAdSize)
868
- __AdSizeFromString:
869
- (NSString *)
870
- size
871
- {
872
- if ([size
873
- isEqualToString:
874
- @"ANCHOR"
875
- @"ED"])
876
- {
877
- return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth (
878
- adWidth);
879
- }
880
- else if (
881
- [size
882
- isEqualToString:
883
- @"IN_"
884
- @"LINE"])
885
- {
886
- return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth (
887
- adWidth);
888
- }
889
- else if (
890
- [size
891
- isEqualToString:
892
- @"BANNE"
893
- @"R"])
894
- {
895
- return GADAdSizeBanner;
896
- }
897
- else if (
898
- [size
899
- isEqualToString:
900
- @"LARGE_"
901
- @"BANNE"
902
- @"R"])
903
- {
904
- return GADAdSizeLargeBanner;
905
- }
906
- else if (
907
- [size
908
- isEqualToString:
909
- @"FULL_"
910
- @"BANNE"
911
- @"R"])
912
- {
913
- return GADAdSizeFullBanner;
914
- }
915
- else if (
916
- [size
917
- isEqualToString:
918
- @"LEADER"
919
- @"BOAR"
920
- @"D"])
921
- {
922
- return GADAdSizeLeaderboard;
923
- }
924
- else
925
- {
926
- return GADAdSizeBanner;
927
- }
553
+
554
+
555
+
556
+
557
+ - (void)pluginInitialize {
558
+ [super pluginInitialize];
559
+
560
+ [[NSNotificationCenter defaultCenter] addObserver:self
561
+ selector:@selector(orientationDidChange:)
562
+ name:UIDeviceOrientationDidChangeNotification
563
+ object:nil];
564
+
565
+ isIAB = YES;
566
+ NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
567
+ NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
568
+ NSNumber *CmpSdkID = [prefs valueForKey:@"IABTCF"
569
+ @"_CmpSd"
570
+ @"kID"];
571
+ NSString *gdprApplies = [prefs stringForKey:@"IABTCF"
572
+ @"_gdprA"
573
+ @"pplie"
574
+ @"s"];
575
+ NSString *PurposeConsents = [prefs stringForKey:@"IABTCF"
576
+ @"_Purpo"
577
+ @"seCons"
578
+ @"ents"];
579
+ NSString *TCString = [prefs stringForKey:@"IABTCF"
580
+ @"_TCStr"
581
+ @"ing"];
582
+ result[@"IABTCF_"
583
+ @"CmpSdkID"] = CmpSdkID;
584
+ result[@"IABTCF_"
585
+ @"gdprApplies"] = gdprApplies;
586
+ result[@"IABTCF_"
587
+ @"PurposeCons"
588
+ @"ents"] = PurposeConsents;
589
+ result[@"IABTCF_"
590
+ @"TCString"] = TCString;
591
+ // NSLog(@"%@",
592
+ // [[NSUserDefaults
593
+ // standardUserDefaults]
594
+ // dictionaryRepresentation]);
595
+ [prefs synchronize];
596
+
597
+
598
+
928
599
  }
929
- - (void)loadBannerAd:
930
- (CDVInvokedUrlCommand
931
- *)command
932
- {
933
600
 
934
- CDVPluginResult
935
- *pluginResult;
936
- NSString *callbackId
937
- = command
938
- .callbackId;
939
- adFormat = 3;
940
- if (adFormat == 3)
941
- {
942
- dispatch_async (dispatch_get_main_queue (), ^{
943
- UIView
944
- *parentView
945
- = [self.webView
946
- superview];
947
- NSString
948
- *adUnitId
949
- = [command
950
- .arguments
951
- objectAtIndex:
952
- 0];
953
- NSString
954
- *position
955
- = [command
956
- .arguments
957
- objectAtIndex:
958
- 1];
959
- NSString *size =
960
- [command.arguments
961
- objectAtIndex:
962
- 2];
963
- NSString
964
- *collapsible
965
- = [command
966
- .arguments
967
- objectAtIndex:
968
- 3];
969
- NSNumber *
970
- adaptive_Width
971
- = [command
972
- .arguments
973
- objectAtIndex:
974
- 4];
975
- BOOL autoShow = [[command
976
- argumentAtIndex:
977
- 5]
978
- boolValue];
979
- auto_Show
980
- = autoShow;
981
- int intValue =
982
- [adaptive_Width
983
- intValue];
984
- adWidth
985
- = intValue;
986
- Position
987
- = position;
988
- GADAdSize sizes = [self
989
- __AdSizeFromString:
990
- size];
991
- self.bannerView =
992
- [[GADBannerView
993
- alloc]
994
- initWithAdSize:
995
- sizes];
996
- GADRequest
997
- *request
998
- = [GADRequest
999
- request];
1000
- GADExtras *extras
1001
- = [[GADExtras
1002
- alloc]
1003
- init];
1004
- if (EnableCollapsible)
1005
- {
1006
- extras
1007
- .additionalParameters
1008
- = @{
1009
- @"colla"
1010
- @"psibl"
1011
- @"e" :
1012
- collapsible
1013
- };
1014
- }
1015
- extras
1016
- .additionalParameters
1017
- = @{
1018
- @"npa" :
1019
- Npa
1020
- };
1021
- [request
1022
- registerAdNetworkExtras:
1023
- extras];
1024
- self.bannerView
1025
- .adUnitID
1026
- = adUnitId;
1027
- self.bannerView
1028
- .rootViewController
1029
- = self.viewController;
1030
- self.bannerView
1031
- .delegate
1032
- = self;
1033
- [self.bannerView
1034
- loadRequest:
1035
- request];
1036
- self.bannerView
1037
- .hidden
1038
- = YES;
1039
- [parentView
1040
- addSubview:
1041
- self.bannerView];
1042
- [parentView
1043
- bringSubviewToFront:
1044
- self.bannerView];
1045
- });
1046
- pluginResult = [CDVPluginResult
1047
- resultWithStatus:
1048
- CDVCommandStatus_OK];
1049
- }
1050
- else
1051
- {
1052
- NSLog (
1053
- @"Admob "
1054
- @"Option "
1055
- @"invalid for "
1056
- @"banner");
1057
- pluginResult = [CDVPluginResult
1058
- resultWithStatus:
1059
- CDVCommandStatus_ERROR];
1060
- }
1061
- [self.commandDelegate
1062
- sendPluginResult:
1063
- pluginResult
1064
- callbackId:
1065
- callbackId];
601
+
602
+
603
+
604
+
605
+
606
+ - (void)orientationDidChange:(NSNotification *)notification {
607
+ // NSLog(@"Orientation changed");
608
+ [self fireEvent:@"" event:@"on.screen.rotated" withData:nil];
609
+ if (isAutoResize) {
610
+ dispatch_async(dispatch_get_main_queue(), ^{
611
+ @try {
612
+
613
+ if (self.bannerView) {
614
+ UIView *parentView = self.bannerView.superview;
615
+ if (parentView != nil) {
616
+ [self.bannerView removeFromSuperview];
617
+ }
618
+ }
619
+
620
+ self.bannerViewLayout = [[UIView alloc] initWithFrame:CGRectZero];
621
+ self.bannerViewLayout.translatesAutoresizingMaskIntoConstraints = NO;
622
+
623
+ UIView *rootView = self.viewController.view;
624
+ if ([rootView isKindOfClass:[UIView class]]) {
625
+ [rootView addSubview:self.bannerViewLayout];
626
+
627
+
628
+ [self.bannerViewLayout.topAnchor constraintEqualToAnchor:rootView.topAnchor].active = YES;
629
+ [self.bannerViewLayout.leadingAnchor constraintEqualToAnchor:rootView.leadingAnchor].active = YES;
630
+ [self.bannerViewLayout.trailingAnchor constraintEqualToAnchor:rootView.trailingAnchor].active = YES;
631
+ [self.bannerViewLayout.heightAnchor constraintEqualToConstant:50].active = YES;
632
+ }
633
+
634
+
635
+ self.bannerView = [[GADBannerView alloc] initWithAdSize:GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(rootView.frame.size.width)];
636
+ self.bannerView.adUnitID = bannerSaveAdUnitId;
637
+ self.bannerView.delegate = self;
638
+ [self.bannerView loadRequest:[GADRequest request]];
639
+
640
+
641
+ [self.bannerViewLayout addSubview:self.bannerView];
642
+ [self.bannerViewLayout bringSubviewToFront:self.bannerView];
643
+
644
+ } @catch (NSException *exception) {
645
+ // NSLog(@"Error adjusting banner size: %@", exception.reason);
646
+ // PUBLIC_CALLBACKS.error([NSString stringWithFormat:@"Error adjusting banner size: %@", exception.reason]);
647
+ }
648
+ });
649
+ }
1066
650
  }
1067
- - (void)showBannerAd:
1068
- (CDVInvokedUrlCommand
1069
- *)command
1070
- {
1071
- CDVPluginResult
1072
- *pluginResult;
1073
- NSString *callbackId
1074
- = command
1075
- .callbackId;
1076
- if (self.bannerView)
1077
- {
1078
- self.bannerView
1079
- .hidden
1080
- = NO;
1081
- [self
1082
- addBannerViewToView:
1083
- command];
1084
- pluginResult = [CDVPluginResult
1085
- resultWithStatus:
1086
- CDVCommandStatus_OK];
1087
- }
1088
- else
1089
- {
1090
- [self
1091
- fireEvent:@""
1092
- event:
1093
- @"on."
1094
- @"bann"
1095
- @"er."
1096
- @"fail"
1097
- @"ed."
1098
- @"show"
1099
- withData:nil];
1100
- pluginResult = [CDVPluginResult
1101
- resultWithStatus:
1102
- CDVCommandStatus_ERROR];
1103
- }
1104
- [self.commandDelegate
1105
- sendPluginResult:
1106
- pluginResult
1107
- callbackId:
1108
- callbackId];
651
+
652
+
653
+
654
+
655
+
656
+
657
+ - (void)addBannerConstraints {
658
+ self.bannerView.translatesAutoresizingMaskIntoConstraints = NO;
659
+
660
+ // Tambahkan constraint berdasarkan posisi
661
+ if ([Position isEqualToString:@"bottom-center"]) {
662
+ [self.viewController.view addConstraints:@[
663
+ [NSLayoutConstraint constraintWithItem:self.bannerView
664
+ attribute:NSLayoutAttributeBottom
665
+ relatedBy:NSLayoutRelationEqual
666
+ toItem:self.viewController.view.safeAreaLayoutGuide
667
+ attribute:NSLayoutAttributeBottom
668
+ multiplier:1
669
+ constant:0],
670
+ [NSLayoutConstraint constraintWithItem:self.bannerView
671
+ attribute:NSLayoutAttributeCenterX
672
+ relatedBy:NSLayoutRelationEqual
673
+ toItem:self.viewController.view
674
+ attribute:NSLayoutAttributeCenterX
675
+ multiplier:1
676
+ constant:0]
677
+ ]];
678
+ } else if ([Position isEqualToString:@"top-center"]) {
679
+ [self.viewController.view addConstraints:@[
680
+ [NSLayoutConstraint constraintWithItem:self.bannerView
681
+ attribute:NSLayoutAttributeTop
682
+ relatedBy:NSLayoutRelationEqual
683
+ toItem:self.viewController.view.safeAreaLayoutGuide
684
+ attribute:NSLayoutAttributeTop
685
+ multiplier:1
686
+ constant:0],
687
+ [NSLayoutConstraint constraintWithItem:self.bannerView
688
+ attribute:NSLayoutAttributeCenterX
689
+ relatedBy:NSLayoutRelationEqual
690
+ toItem:self.viewController.view
691
+ attribute:NSLayoutAttributeCenterX
692
+ multiplier:1
693
+ constant:0]
694
+ ]];
695
+ }
1109
696
  }
1110
- - (void)
1111
- addBannerViewToView:
1112
- (CDVInvokedUrlCommand
1113
- *)command
1114
- {
1115
- bannerView
1116
- .translatesAutoresizingMaskIntoConstraints
1117
- = NO;
1118
- [self.viewController
1119
- .view
1120
- addSubview:
1121
- bannerView];
1122
- if ([Position
1123
- isEqualToString:
1124
- @"bottom"
1125
- @"-cente"
1126
- @"r"])
1127
- {
1128
- [self.viewController
1129
- .view addConstraints:@[
1130
- [NSLayoutConstraint
1131
- constraintWithItem:
1132
- bannerView
1133
- attribute:
1134
- NSLayoutAttributeBottom
1135
- relatedBy:
1136
- NSLayoutRelationEqual
1137
- toItem:
1138
- self.viewController
1139
- .view
1140
- .safeAreaLayoutGuide
1141
- attribute:
1142
- NSLayoutAttributeBottom
1143
- multiplier:
1144
- 1
1145
- constant:
1146
- 0],
1147
- [NSLayoutConstraint
1148
- constraintWithItem:
1149
- bannerView
1150
- attribute:
1151
- NSLayoutAttributeCenterX
1152
- relatedBy:
1153
- NSLayoutRelationEqual
1154
- toItem:
1155
- self.viewController
1156
- .view
1157
- attribute:
1158
- NSLayoutAttributeCenterX
1159
- multiplier:
1160
- 1
1161
- constant:
1162
- 0]
1163
- ]];
1164
- }
1165
- else
1166
- {
1167
- [self.viewController
1168
- .view addConstraints:@[
1169
- [NSLayoutConstraint
1170
- constraintWithItem:
1171
- bannerView
1172
- attribute:
1173
- NSLayoutAttributeTop
1174
- relatedBy:
1175
- NSLayoutRelationEqual
1176
- toItem:
1177
- self.viewController
1178
- .view
1179
- .safeAreaLayoutGuide
1180
- attribute:
1181
- NSLayoutAttributeTop
1182
- multiplier:
1183
- 1
1184
- constant:
1185
- 0],
1186
- [NSLayoutConstraint
1187
- constraintWithItem:
1188
- bannerView
1189
- attribute:
1190
- NSLayoutAttributeCenterX
1191
- relatedBy:
1192
- NSLayoutRelationEqual
1193
- toItem:
1194
- self.viewController
1195
- .view
1196
- attribute:
1197
- NSLayoutAttributeCenterX
1198
- multiplier:
1199
- 1
1200
- constant:
1201
- 0]
1202
- ]];
1203
- }
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+ - (void)loadBannerAd:(CDVInvokedUrlCommand *)command {
706
+ CDVPluginResult *pluginResult;
707
+ NSString *callbackId = command.callbackId;
708
+ adFormat = 3;
709
+ NSDictionary *options = [command.arguments objectAtIndex:0];
710
+ NSString *adUnitId = [options valueForKey:@"adUnitId"];
711
+ NSString *position = [options valueForKey:@"position"];
712
+ NSString *collapsible = [options valueForKey:@"collapsible"];
713
+ BOOL autoResize = [[options valueForKey:@"autoResize"] boolValue];
714
+ NSString *size = [options valueForKey:@"size"];
715
+ BOOL autoShow = [[options valueForKey:@"autoShow"] boolValue];
716
+
717
+ bannerSaveAdUnitId = adUnitId;
718
+
719
+ if (adUnitId == nil || [adUnitId length] == 0) {
720
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Ad unit ID is required"];
721
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
722
+ return;
723
+ }
724
+
725
+ if (collapsible != nil && [collapsible length] > 0) {
726
+ enableCollapsible = YES;
727
+ } else {
728
+ enableCollapsible = NO;
729
+ }
730
+
731
+ if (autoResize) {
732
+
733
+ isAutoResize = YES;
734
+ }
735
+
736
+ if (adFormat == 3) {
737
+ dispatch_async(dispatch_get_main_queue(), ^{
738
+
739
+ UIView *parentView = [self.webView superview];
740
+ CGRect frame = self.bannerView.frame;
741
+
742
+ if (@available(iOS 11.0, *)) {
743
+ UIEdgeInsets safeAreaInsets = self.bannerView.safeAreaInsets;
744
+ frame = UIEdgeInsetsInsetRect(frame, safeAreaInsets);
745
+ }
746
+
747
+ self.viewWidth = frame.size.width;
748
+
749
+ auto_Show = autoShow;
750
+ adWidth = self.viewWidth;
751
+
752
+ Position = position;
753
+
754
+ GADAdSize sizes = [self __AdSizeFromString:size];
755
+ self.bannerView = [[GADBannerView alloc] initWithAdSize:sizes];
756
+
757
+ GADRequest *request = [GADRequest request];
758
+ GADExtras *extras = [[GADExtras alloc] init];
759
+
760
+ if (enableCollapsible) {
761
+ extras.additionalParameters = @{@"collapsible" : collapsible};
762
+ }
763
+
764
+ [request registerAdNetworkExtras:extras];
765
+
766
+ self.bannerView.adUnitID = adUnitId;
767
+ self.bannerView.rootViewController = self.viewController;
768
+ self.bannerView.delegate = self;
769
+ [self.bannerView loadRequest:request];
770
+ self.bannerView.hidden = YES;
771
+ [parentView addSubview:self.bannerView];
772
+ [parentView bringSubviewToFront:self.bannerView];
773
+ });
774
+
775
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
776
+ } else {
777
+ // NSLog(@"Admob Option invalid for banner");
778
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
779
+ }
780
+
781
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1204
782
  }
1205
- - (void)hideBannerAd:
1206
- (CDVInvokedUrlCommand
1207
- *)command
1208
- {
1209
- CDVPluginResult
1210
- *pluginResult;
1211
- NSString *callbackId
1212
- = command
1213
- .callbackId;
1214
- if (self.bannerView)
1215
- {
1216
- dispatch_async (
1217
- dispatch_get_main_queue (),
1218
- ^{
1219
- self.bannerView
1220
- .hidden
1221
- = YES;
1222
- [self
1223
- fireEvent:
1224
- @""
1225
- event:
1226
- @"on.banner.hide"
1227
- withData:
1228
- nil];
1229
- });
1230
- pluginResult = [CDVPluginResult
1231
- resultWithStatus:
1232
- CDVCommandStatus_OK];
1233
- }
1234
- else
1235
- {
1236
- pluginResult = [CDVPluginResult
1237
- resultWithStatus:
1238
- CDVCommandStatus_ERROR];
1239
- }
1240
- [self.commandDelegate
1241
- sendPluginResult:
1242
- pluginResult
1243
- callbackId:
1244
- callbackId];
783
+
784
+
785
+ - (GADAdSize)__AdSizeFromString:(NSString *)size {
786
+
787
+ if (self.viewWidth == 0) {
788
+ self.viewWidth = [UIScreen mainScreen].bounds.size.width;
789
+ }
790
+
791
+ if ([size isEqualToString:@"responsive_adaptive"]) {
792
+ return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(self.viewWidth);
793
+ } else if ([size isEqualToString:@"in_line_adaptive"]) {
794
+ return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(self.viewWidth);
795
+ } else if ([size isEqualToString:@"banner"]) {
796
+ return GADAdSizeBanner;
797
+ } else if ([size isEqualToString:@"large_banner"]) {
798
+ return GADAdSizeLargeBanner;
799
+ } else if ([size isEqualToString:@"full_banner"]) {
800
+ return GADAdSizeFullBanner;
801
+ } else if ([size isEqualToString:@"leaderboard"]) {
802
+ return GADAdSizeLeaderboard;
803
+ } else {
804
+ return GADAdSizeBanner;
805
+ }
1245
806
  }
1246
- - (void)removeBannerAd:
1247
- (CDVInvokedUrlCommand
1248
- *)command
1249
- {
1250
- CDVPluginResult
1251
- *pluginResult;
1252
- NSString *callbackId
1253
- = command
1254
- .callbackId;
1255
- if (self.bannerView)
1256
- {
1257
- dispatch_async (
1258
- dispatch_get_main_queue (),
1259
- ^{
1260
- self.bannerView
1261
- .hidden
1262
- = YES;
1263
- [self.bannerView
1264
- removeFromSuperview];
1265
- self.bannerView
1266
- = nil;
1267
- [self
1268
- fireEvent:
1269
- @""
1270
- event:
1271
- @"on.banner.remove"
1272
- withData:
1273
- nil];
1274
- });
1275
- pluginResult = [CDVPluginResult
1276
- resultWithStatus:
1277
- CDVCommandStatus_OK];
1278
- }
1279
- else
1280
- {
1281
- pluginResult = [CDVPluginResult
1282
- resultWithStatus:
1283
- CDVCommandStatus_ERROR];
1284
- }
1285
- [self.commandDelegate
1286
- sendPluginResult:
1287
- pluginResult
1288
- callbackId:
1289
- callbackId];
807
+
808
+
809
+
810
+
811
+ - (void)showBannerAd:(CDVInvokedUrlCommand *)command {
812
+ CDVPluginResult *pluginResult;
813
+ NSString *callbackId = command.callbackId;
814
+ if (self.bannerView) {
815
+ self.bannerView.hidden = NO;
816
+ [self addBannerViewToView:command];
817
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
818
+ } else {
819
+ [self fireEvent:@""
820
+ event:@"on."
821
+ @"bann"
822
+ @"er."
823
+ @"fail"
824
+ @"ed."
825
+ @"show"
826
+ withData:nil];
827
+ pluginResult =
828
+ [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
829
+ }
830
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1290
831
  }
1291
- - (void)loadAppOpenAd:
1292
- (CDVInvokedUrlCommand
1293
- *)command
1294
- {
1295
- CDVPluginResult
1296
- *pluginResult;
1297
- NSString *callbackId
1298
- = command
1299
- .callbackId;
1300
- NSString *adUnitId =
1301
- [command.arguments
1302
- objectAtIndex:
1303
- 0];
1304
- BOOL autoShow = [[command
1305
- argumentAtIndex:
1306
- 1]
1307
- boolValue];
1308
- auto_Show = autoShow;
1309
- adFormat = 1;
1310
- self.appOpenAd = nil;
1311
- if (adFormat == 1)
1312
- {
1313
- dispatch_async (dispatch_get_main_queue (), ^{
1314
- GADRequest
1315
- *request
1316
- = [GADRequest
1317
- request];
1318
- GADExtras *extras
1319
- = [[GADExtras
1320
- alloc]
1321
- init];
1322
- extras
1323
- .additionalParameters
1324
- = @{
1325
- @"npa" :
1326
- Npa
1327
- };
1328
- [request
1329
- registerAdNetworkExtras:
1330
- extras];
1331
- [GADAppOpenAd
1332
- loadWithAdUnitID:
1333
- adUnitId
1334
- request:
1335
- request
1336
- orientation:
1337
- UIInterfaceOrientationPortrait
1338
-
1339
- completionHandler:^(
1340
- GADAppOpenAd
1341
- *ad,
1342
- NSError *
1343
- error) {
1344
- if (error)
1345
- {
1346
- [self
1347
- fireEvent:
1348
- @""
1349
- event:
1350
- @"on.appOpenAd.failed.loaded"
1351
- withData:
1352
- nil];
1353
- NSLog (
1354
- @"Fa"
1355
- @"il"
1356
- @"ed"
1357
- @" t"
1358
- @"o "
1359
- @"lo"
1360
- @"ad"
1361
- @" A"
1362
- @"pp"
1363
- @" O"
1364
- @"pe"
1365
- @"n "
1366
- @"Ad"
1367
- @" a"
1368
- @"d "
1369
- @"wi"
1370
- @"th"
1371
- @" e"
1372
- @"rr"
1373
- @"or"
1374
- @": "
1375
- @"%"
1376
- @"@",
1377
- [error
1378
- localizedDescription]);
1379
- return;
1380
- }
1381
- self.appOpenAd
1382
- = ad;
1383
- self.appOpenAd
1384
- .fullScreenContentDelegate
1385
- = self;
1386
- [self
1387
- fireEvent:
1388
- @""
1389
- event:
1390
- @"on.appOpenAd.loaded"
1391
- withData:
1392
- nil];
1393
- if (auto_Show)
1394
- {
1395
- if (self.appOpenAd
1396
- &&
1397
- [self.appOpenAd
1398
- canPresentFromRootViewController:
1399
- self.viewController
1400
- error:
1401
- nil])
1402
- {
1403
- [self.appOpenAd
1404
- presentFromRootViewController:
1405
- self.viewController];
1406
- }
1407
- else
1408
- {
1409
- [self
1410
- fireEvent:
1411
- @""
1412
- event:
1413
- @"on.appOpenAd.failed.show"
1414
- withData:
1415
- nil];
1416
- }
1417
- }
1418
- }];
1419
- });
1420
- pluginResult = [CDVPluginResult
1421
- resultWithStatus:
1422
- CDVCommandStatus_OK];
1423
- }
1424
- [self.commandDelegate
1425
- sendPluginResult:
1426
- pluginResult
1427
- callbackId:
1428
- callbackId];
832
+
833
+
834
+
835
+
836
+ - (void)addBannerViewToView:(CDVInvokedUrlCommand *)command {
837
+ bannerView.translatesAutoresizingMaskIntoConstraints = NO;
838
+ [self.viewController.view addSubview:bannerView];
839
+ if ([Position isEqualToString:@"bottom-center"]) {
840
+ [self.viewController.view addConstraints:@[
841
+ [NSLayoutConstraint
842
+ constraintWithItem:bannerView
843
+ attribute:NSLayoutAttributeBottom
844
+ relatedBy:NSLayoutRelationEqual
845
+ toItem:self.viewController.view.safeAreaLayoutGuide
846
+ attribute:NSLayoutAttributeBottom
847
+ multiplier:1
848
+ constant:0],
849
+ [NSLayoutConstraint constraintWithItem:bannerView
850
+ attribute:NSLayoutAttributeCenterX
851
+ relatedBy:NSLayoutRelationEqual
852
+ toItem:self.viewController.view
853
+ attribute:NSLayoutAttributeCenterX
854
+ multiplier:1
855
+ constant:0]
856
+ ]];
857
+ } else if ([Position isEqualToString:@"top-center"]) {
858
+
859
+ [self.viewController.view addConstraints:@[
860
+ [NSLayoutConstraint
861
+ constraintWithItem:bannerView
862
+ attribute:NSLayoutAttributeTop
863
+ relatedBy:NSLayoutRelationEqual
864
+ toItem:self.viewController.view.safeAreaLayoutGuide
865
+ attribute:NSLayoutAttributeTop
866
+ multiplier:1
867
+ constant:0],
868
+ [NSLayoutConstraint constraintWithItem:bannerView
869
+ attribute:NSLayoutAttributeCenterX
870
+ relatedBy:NSLayoutRelationEqual
871
+ toItem:self.viewController.view
872
+ attribute:NSLayoutAttributeCenterX
873
+ multiplier:1
874
+ constant:0]
875
+ ]];
876
+
877
+ } else
878
+ {
879
+ [self.viewController.view addConstraints:@[
880
+ [NSLayoutConstraint
881
+ constraintWithItem:bannerView
882
+ attribute:NSLayoutAttributeBottom
883
+ relatedBy:NSLayoutRelationEqual
884
+ toItem:self.viewController.view.safeAreaLayoutGuide
885
+ attribute:NSLayoutAttributeTop
886
+ multiplier:1
887
+ constant:0],
888
+ [NSLayoutConstraint constraintWithItem:bannerView
889
+ attribute:NSLayoutAttributeCenterX
890
+ relatedBy:NSLayoutRelationEqual
891
+ toItem:self.viewController.view
892
+ attribute:NSLayoutAttributeCenterX
893
+ multiplier:1
894
+ constant:0]
895
+ ]];
896
+ }
1429
897
  }
1430
- - (void)showAppOpenAd:
1431
- (CDVInvokedUrlCommand
1432
- *)command
1433
- {
1434
- CDVPluginResult
1435
- *pluginResult;
1436
- NSString *callbackId
1437
- = command
1438
- .callbackId;
1439
- if (self.appOpenAd &&
1440
- [self.appOpenAd
1441
- canPresentFromRootViewController:
1442
- self.viewController
1443
- error:
1444
- nil])
1445
- {
1446
- [self.appOpenAd
1447
- presentFromRootViewController:
1448
- self.viewController];
1449
- pluginResult = [CDVPluginResult
1450
- resultWithStatus:
1451
- CDVCommandStatus_OK];
1452
- }
1453
- else
1454
- {
1455
- pluginResult = [CDVPluginResult
1456
- resultWithStatus:
1457
- CDVCommandStatus_ERROR];
1458
- [self
1459
- fireEvent:@""
1460
- event:
1461
- @"on."
1462
- @"appO"
1463
- @"penA"
1464
- @"d."
1465
- @"fail"
1466
- @"ed."
1467
- @"show"
1468
- withData:nil];
1469
- }
1470
- [self.commandDelegate
1471
- sendPluginResult:
1472
- pluginResult
1473
- callbackId:
1474
- callbackId];
898
+ - (void)hideBannerAd:(CDVInvokedUrlCommand *)command {
899
+ CDVPluginResult *pluginResult;
900
+ NSString *callbackId = command.callbackId;
901
+ if (self.bannerView) {
902
+ dispatch_async(dispatch_get_main_queue(), ^{
903
+ self.bannerView.hidden = YES;
904
+ [self fireEvent:@"" event:@"on.banner.hide" withData:nil];
905
+ });
906
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
907
+ } else {
908
+ pluginResult =
909
+ [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
910
+ }
911
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1475
912
  }
1476
- - (void)
1477
- loadInterstitialAd:
1478
- (CDVInvokedUrlCommand
1479
- *)command
1480
- {
1481
- CDVPluginResult
1482
- *pluginResult;
1483
- NSString *callbackId
1484
- = command
1485
- .callbackId;
1486
- NSString *adUnitId =
1487
- [command.arguments
1488
- objectAtIndex:
1489
- 0];
1490
- BOOL autoShow = [[command
1491
- argumentAtIndex:
1492
- 1]
1493
- boolValue];
1494
- auto_Show = autoShow;
1495
- adFormat = 2;
1496
- if (adFormat == 2)
1497
- {
1498
- dispatch_async (dispatch_get_main_queue (), ^{
1499
- GADRequest
1500
- *request
1501
- = [GADRequest
1502
- request];
1503
- [GADInterstitialAd
1504
- loadWithAdUnitID:
1505
- adUnitId
1506
- request:
1507
- request
1508
- completionHandler:^(
1509
- GADInterstitialAd
1510
- *ad,
1511
- NSError *
1512
- error) {
1513
- if (error)
1514
- {
1515
- NSLog (
1516
- @"Fa"
1517
- @"il"
1518
- @"ed"
1519
- @" t"
1520
- @"o "
1521
- @"lo"
1522
- @"ad"
1523
- @" i"
1524
- @"nt"
1525
- @"er"
1526
- @"st"
1527
- @"it"
1528
- @"ia"
1529
- @"l "
1530
- @"ad"
1531
- @" w"
1532
- @"it"
1533
- @"h "
1534
- @"er"
1535
- @"ro"
1536
- @"r:"
1537
- @" %"
1538
- @"@",
1539
- [error
1540
- localizedDescription]);
1541
- }
1542
- self.interstitial
1543
- = ad;
1544
- self.interstitial
1545
- .fullScreenContentDelegate
1546
- = self;
1547
- [self
1548
- fireEvent:
1549
- @""
1550
- event:
1551
- @"on.interstitial.loaded"
1552
- withData:
1553
- nil];
1554
- if (auto_Show)
1555
- {
1556
- if (self.interstitial
1557
- &&
1558
- [self.interstitial
1559
- canPresentFromRootViewController:
1560
- self.viewController
1561
- error:
1562
- nil])
1563
- {
1564
- [self.interstitial
1565
- presentFromRootViewController:
1566
- self.viewController];
1567
- }
1568
- else
1569
- {
1570
- [self
1571
- fireEvent:
1572
- @""
1573
- event:
1574
- @"on.interstitial.failed.show"
1575
- withData:
1576
- nil];
1577
- }
1578
- }
1579
- }];
1580
- });
1581
- }
1582
- pluginResult = [CDVPluginResult
1583
- resultWithStatus:
1584
- CDVCommandStatus_OK];
1585
- [self.commandDelegate
1586
- sendPluginResult:
1587
- pluginResult
1588
- callbackId:
1589
- callbackId];
913
+ - (void)removeBannerAd:(CDVInvokedUrlCommand *)command {
914
+ CDVPluginResult *pluginResult;
915
+ NSString *callbackId = command.callbackId;
916
+ if (self.bannerView) {
917
+ dispatch_async(dispatch_get_main_queue(), ^{
918
+ self.bannerView.hidden = YES;
919
+ [self.bannerView removeFromSuperview];
920
+ self.bannerView = nil;
921
+ [self fireEvent:@"" event:@"on.banner.remove" withData:nil];
922
+ });
923
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
924
+ } else {
925
+ pluginResult =
926
+ [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
927
+ }
928
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1590
929
  }
1591
- - (void)
1592
- showInterstitialAd:
1593
- (CDVInvokedUrlCommand
1594
- *)command
1595
- {
1596
- CDVPluginResult
1597
- *pluginResult;
1598
- NSString *callbackId
1599
- = command
1600
- .callbackId;
1601
- if (self.interstitial
1602
- &&
1603
- [self.interstitial
1604
- canPresentFromRootViewController:
1605
- self.viewController
1606
- error:
1607
- nil])
1608
- {
1609
- [self.interstitial
1610
- presentFromRootViewController:
1611
- self.viewController];
1612
- pluginResult = [CDVPluginResult
1613
- resultWithStatus:
1614
- CDVCommandStatus_OK];
1615
- }
1616
- else
1617
- {
1618
- pluginResult = [CDVPluginResult
1619
- resultWithStatus:
1620
- CDVCommandStatus_ERROR];
1621
- [self
1622
- fireEvent:@""
1623
- event:
1624
- @"on."
1625
- @"inte"
1626
- @"rsti"
1627
- @"tial"
1628
- @".fai"
1629
- @"led."
1630
- @"show"
1631
- withData:nil];
1632
- }
1633
- [self.commandDelegate
1634
- sendPluginResult:
1635
- pluginResult
1636
- callbackId:
1637
- callbackId];
930
+ - (void)loadAppOpenAd:(CDVInvokedUrlCommand *)command {
931
+ CDVPluginResult *pluginResult;
932
+ NSString *callbackId = command.callbackId;
933
+ NSDictionary *options = [command.arguments objectAtIndex:0];
934
+ NSString *adUnitId = [options valueForKey:@"adUnitId"];
935
+ BOOL autoShow = [[options valueForKey:@"autoShow"] boolValue];
936
+ auto_Show = autoShow;
937
+ adFormat = 1;
938
+ self.appOpenAd = nil;
939
+ if (adFormat == 1) {
940
+ dispatch_async(dispatch_get_main_queue(), ^{
941
+ GADRequest *request = [GADRequest request];
942
+ GADExtras *extras = [[GADExtras alloc] init];
943
+ // extras.additionalParameters = @{@"npa" : Npa}; // Deprecated
944
+ [request registerAdNetworkExtras:extras];
945
+ [GADAppOpenAd
946
+ loadWithAdUnitID:adUnitId
947
+ request:request
948
+ completionHandler:^(GADAppOpenAd *ad, NSError *error) {
949
+ if (error) {
950
+ [self fireEvent:@""
951
+ event:@"on.appOpenAd.failed.loaded"
952
+ withData:nil];
953
+ NSLog(@"Fa"
954
+ @"il"
955
+ @"ed"
956
+ @" t"
957
+ @"o "
958
+ @"lo"
959
+ @"ad"
960
+ @" A"
961
+ @"pp"
962
+ @" O"
963
+ @"pe"
964
+ @"n "
965
+ @"Ad"
966
+ @" a"
967
+ @"d "
968
+ @"wi"
969
+ @"th"
970
+ @" e"
971
+ @"rr"
972
+ @"or"
973
+ @": "
974
+ @"%"
975
+ @"@",
976
+ [error localizedDescription]);
977
+ return;
978
+ }
979
+ self.appOpenAd = ad;
980
+ self.appOpenAd.fullScreenContentDelegate = self;
981
+ [self fireEvent:@"" event:@"on.appOpenAd.loaded" withData:nil];
982
+ if (auto_Show) {
983
+ if (self.appOpenAd &&
984
+ [self.appOpenAd
985
+ canPresentFromRootViewController:self.viewController
986
+ error:nil]) {
987
+ [self.appOpenAd
988
+ presentFromRootViewController:self.viewController];
989
+ } else {
990
+ [self fireEvent:@""
991
+ event:@"on.appOpenAd.failed.show"
992
+ withData:nil];
993
+ }
994
+ }
995
+ }];
996
+ });
997
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
998
+ }
999
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1638
1000
  }
1639
- - (void)
1640
- loadRewardedInterstitialAd:
1641
- (CDVInvokedUrlCommand
1642
- *)command
1643
- {
1644
- CDVPluginResult
1645
- *pluginResult;
1646
- NSString *callbackId
1647
- = command
1648
- .callbackId;
1649
- NSString *adUnitId =
1650
- [command.arguments
1651
- objectAtIndex:
1652
- 0];
1653
- BOOL autoShow = [[command
1654
- argumentAtIndex:
1655
- 1]
1656
- boolValue];
1657
- auto_Show = autoShow;
1658
- adFormat = 4;
1659
- if (adFormat == 4)
1660
- {
1661
- dispatch_async (
1662
- dispatch_get_main_queue (),
1663
- ^{
1664
- GADRequest
1665
- *request
1666
- = [GADRequest
1667
- request];
1668
- [GADRewardedInterstitialAd loadWithAdUnitID:
1669
- adUnitId
1670
- request:
1671
- request
1672
- completionHandler:
1673
- ^(GADRewardedInterstitialAd *ad, NSError
1674
- *error) {
1675
- if (error)
1676
- {
1677
- NSLog (
1678
- @"Rewarded ad failed to load with error: %@",
1679
- [error
1680
- localizedDescription]);
1681
- return;
1682
- }
1683
- self.rewardedInterstitialAd
1684
- = ad;
1685
- isAdSkip
1686
- = 1;
1687
- NSLog (
1688
- @"Rewarded ad loaded.");
1689
- self.rewardedInterstitialAd
1690
- .fullScreenContentDelegate
1691
- = self;
1692
- [self
1693
- fireEvent:
1694
- @""
1695
- event:
1696
- @"on.rewardedInt.loaded"
1697
- withData:
1698
- nil];
1699
- if (auto_Show)
1700
- {
1701
- if (self.rewardedInterstitialAd
1702
- &&
1703
- [self.rewardedInterstitialAd
1704
- canPresentFromRootViewController:
1705
- self.viewController
1706
- error:
1707
- nil])
1708
- {
1709
- [self.rewardedInterstitialAd presentFromRootViewController:
1710
- self.viewController
1711
- userDidEarnRewardHandler:^{
1712
- GADAdReward
1713
- *reward
1714
- = self.rewardedInterstitialAd
1715
- .adReward;
1716
- [self
1717
- fireEvent:
1718
- @""
1719
- event:
1720
- @"on.rewardedInt.userEarnedReward"
1721
- withData:
1722
- nil];
1723
- isAdSkip
1724
- = 2;
1725
- NSString
1726
- *rewardMessage
1727
- = [NSString
1728
- stringWithFormat:
1729
- @"Reward received with "
1730
- @"currency %@ , amount %ld",
1731
- reward
1732
- .type,
1733
- [reward.amount
1734
- longValue]];
1735
- NSLog (
1736
- @"%@",
1737
- rewardMessage);
1738
- }];
1739
- }
1740
- else
1741
- {
1742
- [self
1743
- fireEvent:
1744
- @""
1745
- event:
1746
- @"on.rewardedInt.failed.show"
1747
- withData:
1748
- nil];
1749
- }
1750
- }
1751
- }];
1752
- });
1753
- }
1754
- pluginResult = [CDVPluginResult
1755
- resultWithStatus:
1756
- CDVCommandStatus_OK];
1757
- [self.commandDelegate
1758
- sendPluginResult:
1759
- pluginResult
1760
- callbackId:
1761
- callbackId];
1001
+ - (void)showAppOpenAd:(CDVInvokedUrlCommand *)command {
1002
+ CDVPluginResult *pluginResult;
1003
+ NSString *callbackId = command.callbackId;
1004
+ if (self.appOpenAd &&
1005
+ [self.appOpenAd canPresentFromRootViewController:self.viewController
1006
+ error:nil]) {
1007
+ [self.appOpenAd presentFromRootViewController:self.viewController];
1008
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1009
+ } else {
1010
+ pluginResult =
1011
+ [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
1012
+ [self fireEvent:@""
1013
+ event:@"on."
1014
+ @"appO"
1015
+ @"penA"
1016
+ @"d."
1017
+ @"fail"
1018
+ @"ed."
1019
+ @"show"
1020
+ withData:nil];
1021
+ }
1022
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1762
1023
  }
1763
- - (void)
1764
- showRewardedInterstitialAd:
1765
- (CDVInvokedUrlCommand
1766
- *)command
1767
- {
1768
- CDVPluginResult
1769
- *pluginResult;
1770
- NSString *callbackId
1771
- = command
1772
- .callbackId;
1773
- if (self.rewardedInterstitialAd
1774
- &&
1775
- [self.rewardedInterstitialAd
1776
- canPresentFromRootViewController:
1777
- self.viewController
1778
- error:
1779
- nil])
1780
- {
1781
- [self.rewardedInterstitialAd
1782
- presentFromRootViewController:
1783
- self.viewController
1784
- userDidEarnRewardHandler:^{
1785
- GADAdReward
1786
- *reward
1787
- = self.rewardedInterstitialAd
1788
- .adReward;
1789
- [self
1790
- fireEvent:
1791
- @""
1792
- event:
1793
- @"on.rewardedInt.userEarnedReward"
1794
- withData:
1795
- nil];
1796
- isAdSkip
1797
- = 2;
1798
- NSString *rewardMessage = [NSString
1799
- stringWithFormat:
1800
- @"Reward received with "
1801
- @"currency %@ , amount %ld",
1802
- reward
1803
- .type,
1804
- [reward.amount
1805
- longValue]];
1806
- NSLog (
1807
- @"%"
1808
- @"@",
1809
- rewardMessage);
1024
+ - (void)loadInterstitialAd:(CDVInvokedUrlCommand *)command {
1025
+ CDVPluginResult *pluginResult;
1026
+ NSString *callbackId = command.callbackId;
1027
+ NSDictionary *options = [command.arguments objectAtIndex:0];
1028
+ NSString *adUnitId = [options valueForKey:@"adUnitId"];
1029
+ BOOL autoShow = [[options valueForKey:@"autoShow"] boolValue];
1030
+ auto_Show = autoShow;
1031
+ adFormat = 2;
1032
+ if (adFormat == 2) {
1033
+ dispatch_async(dispatch_get_main_queue(), ^{
1034
+ GADRequest *request = [GADRequest request];
1035
+ [GADInterstitialAd
1036
+ loadWithAdUnitID:adUnitId
1037
+ request:request
1038
+ completionHandler:^(GADInterstitialAd *ad, NSError *error) {
1039
+ if (error) {
1040
+ NSLog(@"Fa"
1041
+ @"il"
1042
+ @"ed"
1043
+ @" t"
1044
+ @"o "
1045
+ @"lo"
1046
+ @"ad"
1047
+ @" i"
1048
+ @"nt"
1049
+ @"er"
1050
+ @"st"
1051
+ @"it"
1052
+ @"ia"
1053
+ @"l "
1054
+ @"ad"
1055
+ @" w"
1056
+ @"it"
1057
+ @"h "
1058
+ @"er"
1059
+ @"ro"
1060
+ @"r:"
1061
+ @" %"
1062
+ @"@",
1063
+ [error localizedDescription]);
1064
+ }
1065
+ self.interstitial = ad;
1066
+ self.interstitial.fullScreenContentDelegate = self;
1067
+ [self fireEvent:@""
1068
+ event:@"on.interstitial.loaded"
1069
+ withData:nil];
1070
+ if (auto_Show) {
1071
+ if (self.interstitial &&
1072
+ [self.interstitial
1073
+ canPresentFromRootViewController:self.viewController
1074
+ error:nil]) {
1075
+ [self.interstitial
1076
+ presentFromRootViewController:self.viewController];
1077
+ } else {
1078
+ [self fireEvent:@""
1079
+ event:@"on.interstitial.failed.show"
1080
+ withData:nil];
1081
+ }
1082
+ }
1810
1083
  }];
1811
- pluginResult = [CDVPluginResult
1812
- resultWithStatus:
1813
- CDVCommandStatus_OK];
1814
- }
1815
- else
1816
- {
1817
- pluginResult = [CDVPluginResult
1818
- resultWithStatus:
1819
- CDVCommandStatus_ERROR];
1820
- [self
1821
- fireEvent:@""
1822
- event:
1823
- @"on."
1824
- @"rewa"
1825
- @"rded"
1826
- @"Int."
1827
- @"fail"
1828
- @"ed."
1829
- @"show"
1830
- withData:nil];
1831
- }
1832
- [self.commandDelegate
1833
- sendPluginResult:
1834
- pluginResult
1835
- callbackId:
1836
- callbackId];
1084
+ });
1085
+ }
1086
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1087
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1837
1088
  }
1838
- - (void)loadRewardedAd:
1839
- (CDVInvokedUrlCommand
1840
- *)command
1841
- {
1842
- CDVPluginResult
1843
- *pluginResult;
1844
- NSString *callbackId
1845
- = command
1846
- .callbackId;
1847
- NSString *adUnitId =
1848
- [command.arguments
1849
- objectAtIndex:
1850
- 0];
1851
- BOOL autoShow = [[command
1852
- argumentAtIndex:
1853
- 1]
1854
- boolValue];
1855
- auto_Show = autoShow;
1856
- adFormat = 3;
1857
- if (adFormat == 3)
1858
- {
1859
- dispatch_async (
1860
- dispatch_get_main_queue (),
1861
- ^{
1862
- GADRequest
1863
- *request
1864
- = [GADRequest
1865
- request];
1866
- [GADRewardedAd loadWithAdUnitID:
1867
- adUnitId
1868
- request:
1869
- request
1870
- completionHandler:^(
1871
- GADRewardedAd *ad, NSError
1872
- *error) {
1873
- if (error)
1874
- {
1875
- NSLog (
1876
- @"Rewarded ad failed to load with error: %@",
1877
- [error
1878
- localizedDescription]);
1879
- return;
1880
- }
1881
- self.rewardedAd
1882
- = ad;
1883
- NSLog (
1884
- @"Rewarded ad loaded.");
1885
- isAdSkip
1886
- = 0;
1887
- self.rewardedAd
1888
- .fullScreenContentDelegate
1889
- = self;
1890
- [self
1891
- fireEvent:
1892
- @""
1893
- event:
1894
- @"on.rewarded.loaded"
1895
- withData:
1896
- nil];
1897
- if (auto_Show)
1898
- {
1899
- if (self.rewardedAd
1900
- &&
1901
- [self.rewardedAd
1902
- canPresentFromRootViewController:
1903
- self.viewController
1904
- error:
1905
- nil])
1906
- {
1907
- [self.rewardedAd
1908
- presentFromRootViewController:
1909
- self.viewController
1910
- userDidEarnRewardHandler:^{
1911
- GADAdReward
1912
- *reward
1913
- = self.rewardedAd
1914
- .adReward;
1915
- [self
1916
- fireEvent:
1917
- @""
1918
- event:
1919
- @"on.reward.userEarnedReward"
1920
- withData:
1921
- nil];
1922
- isAdSkip
1923
- = 2;
1924
- NSString
1925
- *rewardMessage
1926
- = [NSString
1927
- stringWithFormat:
1928
- @"Reward received with currency "
1929
- @"%@ , amount %lf",
1930
- reward
1931
- .type,
1932
- [reward.amount
1933
- doubleValue]];
1934
- NSLog (
1935
- @"%@",
1936
- rewardMessage);
1937
- }];
1938
- }
1939
- else
1940
- {
1941
- [self
1942
- fireEvent:
1943
- @""
1944
- event:
1945
- @"on.rewarded.failed.show"
1946
- withData:
1947
- nil];
1948
- }
1949
- }
1950
- }];
1951
- });
1952
- }
1953
- pluginResult = [CDVPluginResult
1954
- resultWithStatus:
1955
- CDVCommandStatus_OK];
1956
- [self.commandDelegate
1957
- sendPluginResult:
1958
- pluginResult
1959
- callbackId:
1960
- callbackId];
1089
+ - (void)showInterstitialAd:(CDVInvokedUrlCommand *)command {
1090
+ CDVPluginResult *pluginResult;
1091
+ NSString *callbackId = command.callbackId;
1092
+ if (self.interstitial &&
1093
+ [self.interstitial canPresentFromRootViewController:self.viewController
1094
+ error:nil]) {
1095
+ [self.interstitial presentFromRootViewController:self.viewController];
1096
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1097
+ } else {
1098
+ pluginResult =
1099
+ [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
1100
+ [self fireEvent:@""
1101
+ event:@"on."
1102
+ @"inte"
1103
+ @"rsti"
1104
+ @"tial"
1105
+ @".fai"
1106
+ @"led."
1107
+ @"show"
1108
+ withData:nil];
1109
+ }
1110
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1961
1111
  }
1962
- - (void)showRewardedAd:
1963
- (CDVInvokedUrlCommand
1964
- *)command
1965
- {
1966
- CDVPluginResult
1967
- *pluginResult;
1968
- NSString *callbackId
1969
- = command
1970
- .callbackId;
1971
- if (self.rewardedAd
1972
- &&
1973
- [self.rewardedAd
1974
- canPresentFromRootViewController:
1975
- self.viewController
1976
- error:
1977
- nil])
1978
- {
1979
- [self.rewardedAd
1980
- presentFromRootViewController:
1981
- self.viewController
1982
- userDidEarnRewardHandler:^{
1983
- GADAdReward
1984
- *reward
1985
- = self.rewardedAd
1986
- .adReward;
1987
- [self
1988
- fireEvent:
1989
- @""
1990
- event:
1991
- @"on.reward.userEarnedReward"
1992
- withData:
1993
- nil];
1994
- isAdSkip
1995
- = 2;
1996
- NSString *rewardMessage = [NSString
1997
- stringWithFormat:
1998
- @"Reward received with currency %@ , amount %lf",
1999
- reward
2000
- .type,
2001
- [reward.amount
2002
- doubleValue]];
2003
- NSLog (
2004
- @"%"
1112
+ - (void)loadRewardedInterstitialAd:(CDVInvokedUrlCommand *)command {
1113
+ CDVPluginResult *pluginResult;
1114
+ NSString *callbackId = command.callbackId;
1115
+
1116
+ NSDictionary *options = [command.arguments objectAtIndex:0];
1117
+ NSString *adUnitId = [options valueForKey:@"adUnitId"];
1118
+ BOOL autoShow = [[options valueForKey:@"autoShow"] boolValue];
1119
+
1120
+ auto_Show = autoShow;
1121
+ adFormat = 4;
1122
+ if (adFormat == 4) {
1123
+ dispatch_async(dispatch_get_main_queue(), ^{
1124
+ GADRequest *request = [GADRequest request];
1125
+ [GADRewardedInterstitialAd
1126
+ loadWithAdUnitID:adUnitId
1127
+ request:request
1128
+ completionHandler:^(GADRewardedInterstitialAd *ad,
1129
+ NSError *error) {
1130
+ if (error) {
1131
+ NSLog(@"Rewarded ad failed to load with error: %@",
1132
+ [error localizedDescription]);
1133
+ return;
1134
+ }
1135
+ self.rewardedInterstitialAd = ad;
1136
+ isAdSkip = 1;
1137
+ NSLog(@"Rewarded ad loaded.");
1138
+ self.rewardedInterstitialAd.fullScreenContentDelegate = self;
1139
+ [self fireEvent:@""
1140
+ event:@"on.rewardedInt.loaded"
1141
+ withData:nil];
1142
+ if (auto_Show) {
1143
+ if (self.rewardedInterstitialAd &&
1144
+ [self.rewardedInterstitialAd
1145
+ canPresentFromRootViewController:self.viewController
1146
+ error:nil]) {
1147
+ [self.rewardedInterstitialAd
1148
+ presentFromRootViewController:self.viewController
1149
+ userDidEarnRewardHandler:^{
1150
+ GADAdReward *reward =
1151
+ self.rewardedInterstitialAd.adReward;
1152
+ [self fireEvent:@""
1153
+ event:@"on.rewardedInt."
1154
+ @"userEarnedReward"
1155
+ withData:nil];
1156
+ isAdSkip = 2;
1157
+ NSString *rewardMessage = [NSString
1158
+ stringWithFormat:
1159
+ @"Reward received with "
1160
+ @"currency %@ , amount %ld",
1161
+ reward.type,
1162
+ [reward.amount longValue]];
1163
+ NSLog(@"%@", rewardMessage);
1164
+ }];
1165
+ } else {
1166
+ [self fireEvent:@""
1167
+ event:@"on.rewardedInt.failed.show"
1168
+ withData:nil];
1169
+ }
1170
+ }
1171
+ }];
1172
+ });
1173
+ }
1174
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1175
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1176
+ }
1177
+ - (void)showRewardedInterstitialAd:(CDVInvokedUrlCommand *)command {
1178
+ CDVPluginResult *pluginResult;
1179
+ NSString *callbackId = command.callbackId;
1180
+ if (self.rewardedInterstitialAd &&
1181
+ [self.rewardedInterstitialAd
1182
+ canPresentFromRootViewController:self.viewController
1183
+ error:nil]) {
1184
+ [self.rewardedInterstitialAd
1185
+ presentFromRootViewController:self.viewController
1186
+ userDidEarnRewardHandler:^{
1187
+ GADAdReward *reward = self.rewardedInterstitialAd.adReward;
1188
+ [self fireEvent:@""
1189
+ event:@"on.rewardedInt.userEarnedReward"
1190
+ withData:nil];
1191
+ isAdSkip = 2;
1192
+ NSString *rewardMessage = [NSString
1193
+ stringWithFormat:@"Reward received with "
1194
+ @"currency %@ , amount %ld",
1195
+ reward.type, [reward.amount longValue]];
1196
+ NSLog(@"%"
2005
1197
  @"@",
2006
1198
  rewardMessage);
1199
+ }];
1200
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1201
+ } else {
1202
+ pluginResult =
1203
+ [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
1204
+ [self fireEvent:@""
1205
+ event:@"on."
1206
+ @"rewa"
1207
+ @"rded"
1208
+ @"Int."
1209
+ @"fail"
1210
+ @"ed."
1211
+ @"show"
1212
+ withData:nil];
1213
+ }
1214
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
1215
+ }
1216
+ - (void)loadRewardedAd:(CDVInvokedUrlCommand *)command {
1217
+ CDVPluginResult *pluginResult;
1218
+ NSString *callbackId = command.callbackId;
1219
+ NSDictionary *options = [command.arguments objectAtIndex:0];
1220
+ NSString *adUnitId = [options valueForKey:@"adUnitId"];
1221
+ BOOL autoShow = [[options valueForKey:@"autoShow"] boolValue];
1222
+ auto_Show = autoShow;
1223
+ adFormat = 3;
1224
+ if (adFormat == 3) {
1225
+ dispatch_async(dispatch_get_main_queue(), ^{
1226
+ GADRequest *request = [GADRequest request];
1227
+ [GADRewardedAd
1228
+ loadWithAdUnitID:adUnitId
1229
+ request:request
1230
+ completionHandler:^(GADRewardedAd *ad, NSError *error) {
1231
+ if (error) {
1232
+ NSLog(@"Rewarded ad failed to load with error: %@",
1233
+ [error localizedDescription]);
1234
+ return;
1235
+ }
1236
+ self.rewardedAd = ad;
1237
+ NSLog(@"Rewarded ad loaded.");
1238
+ isAdSkip = 0;
1239
+ self.rewardedAd.fullScreenContentDelegate = self;
1240
+ [self fireEvent:@"" event:@"on.rewarded.loaded" withData:nil];
1241
+ if (auto_Show) {
1242
+ if (self.rewardedAd &&
1243
+ [self.rewardedAd
1244
+ canPresentFromRootViewController:self.viewController
1245
+ error:nil]) {
1246
+ [self.rewardedAd
1247
+ presentFromRootViewController:self.viewController
1248
+ userDidEarnRewardHandler:^{
1249
+ GADAdReward *reward =
1250
+ self.rewardedAd.adReward;
1251
+ [self fireEvent:@""
1252
+ event:@"on.reward.userEarnedReward"
1253
+ withData:nil];
1254
+ isAdSkip = 2;
1255
+ NSString *rewardMessage = [NSString
1256
+ stringWithFormat:
1257
+ @"Reward received with currency "
1258
+ @"%@ , amount %lf",
1259
+ reward.type,
1260
+ [reward.amount doubleValue]];
1261
+ NSLog(@"%@", rewardMessage);
1262
+ }];
1263
+ } else {
1264
+ [self fireEvent:@""
1265
+ event:@"on.rewarded.failed.show"
1266
+ withData:nil];
1267
+ }
1268
+ }
2007
1269
  }];
2008
- pluginResult = [CDVPluginResult
2009
- resultWithStatus:
2010
- CDVCommandStatus_OK];
2011
- }
2012
- else
2013
- {
2014
- pluginResult = [CDVPluginResult
2015
- resultWithStatus:
2016
- CDVCommandStatus_ERROR];
2017
- [self
2018
- fireEvent:@""
2019
- event:
2020
- @"on."
2021
- @"rewa"
2022
- @"rded"
2023
- @".fai"
2024
- @"led."
2025
- @"show"
2026
- withData:nil];
2027
- }
2028
- [self.commandDelegate
2029
- sendPluginResult:
2030
- pluginResult
2031
- callbackId:
2032
- callbackId];
1270
+ });
1271
+ }
1272
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1273
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
2033
1274
  }
2034
- - (void)
2035
- fireEvent:
2036
- (NSString *)
2037
- obj
2038
- event:
2039
- (NSString
2040
- *)
2041
- eventName
2042
- withData:
2043
- (NSString *)
2044
- jsonStr
2045
- {
2046
- NSString *js;
2047
- if (obj &&
2048
- [obj
2049
- isEqualToString:
2050
- @"windo"
2051
- @"w"])
2052
- {
2053
- js = [NSString
2054
- stringWithFormat:
2055
- @"var "
2056
- @"evt="
2057
- @"document"
2058
- @".createE"
2059
- @"vent("
2060
- @"\"UIEven"
2061
- @"ts\");"
2062
- @"evt."
2063
- @"initUIEv"
2064
- @"ent("
2065
- @"\"%@\","
2066
- @"true,"
2067
- @"false,"
2068
- @"window,"
2069
- @"0);"
2070
- @"window."
2071
- @"dispatch"
2072
- @"Event("
2073
- @"evt);",
2074
- eventName];
2075
- }
2076
- else if (jsonStr &&
2077
- [jsonStr
2078
- length]
2079
- > 0)
2080
- {
2081
- js = [NSString
2082
- stringWithFormat:
2083
- @"javascri"
2084
- @"pt:"
2085
- @"cordova."
2086
- @"fireDocu"
2087
- @"mentEven"
2088
- @"t('%@',%"
2089
- @"@);",
2090
- eventName,
2091
- jsonStr];
2092
- }
2093
- else
2094
- {
2095
- js = [NSString
2096
- stringWithFormat:
2097
- @"javascri"
2098
- @"pt:"
2099
- @"cordova."
2100
- @"fireDocu"
2101
- @"mentEven"
2102
- @"t('%@')"
2103
- @";",
2104
- eventName];
2105
- }
2106
- [self.commandDelegate
2107
- evalJs:js];
1275
+ - (void)showRewardedAd:(CDVInvokedUrlCommand *)command {
1276
+ CDVPluginResult *pluginResult;
1277
+ NSString *callbackId = command.callbackId;
1278
+ if (self.rewardedAd &&
1279
+ [self.rewardedAd canPresentFromRootViewController:self.viewController
1280
+ error:nil]) {
1281
+ [self.rewardedAd
1282
+ presentFromRootViewController:self.viewController
1283
+ userDidEarnRewardHandler:^{
1284
+ GADAdReward *reward = self.rewardedAd.adReward;
1285
+ [self fireEvent:@""
1286
+ event:@"on.reward.userEarnedReward"
1287
+ withData:nil];
1288
+ isAdSkip = 2;
1289
+ NSString *rewardMessage = [NSString
1290
+ stringWithFormat:
1291
+ @"Reward received with currency %@ , amount %lf",
1292
+ reward.type, [reward.amount doubleValue]];
1293
+ NSLog(@"%"
1294
+ @"@",
1295
+ rewardMessage);
1296
+ }];
1297
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1298
+ } else {
1299
+ pluginResult =
1300
+ [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
1301
+ [self fireEvent:@""
1302
+ event:@"on."
1303
+ @"rewa"
1304
+ @"rded"
1305
+ @".fai"
1306
+ @"led."
1307
+ @"show"
1308
+ withData:nil];
1309
+ }
1310
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
2108
1311
  }
2109
-
2110
- - (NSString *)
2111
- __getAdMobDeviceId
2112
- {
2113
- NSUUID *adid = [[ASIdentifierManager
2114
- sharedManager]
2115
- advertisingIdentifier];
2116
- return [self
2117
- __md5:
2118
- adid.UUIDString];
1312
+ - (void)fireEvent:(NSString *)obj
1313
+ event:(NSString *)eventName
1314
+ withData:(NSString *)jsonStr {
1315
+ NSString *js;
1316
+ if (obj && [obj isEqualToString:@"windo"
1317
+ @"w"]) {
1318
+ js = [NSString stringWithFormat:@"var "
1319
+ @"evt="
1320
+ @"document"
1321
+ @".createE"
1322
+ @"vent("
1323
+ @"\"UIEven"
1324
+ @"ts\");"
1325
+ @"evt."
1326
+ @"initUIEv"
1327
+ @"ent("
1328
+ @"\"%@\","
1329
+ @"true,"
1330
+ @"false,"
1331
+ @"window,"
1332
+ @"0);"
1333
+ @"window."
1334
+ @"dispatch"
1335
+ @"Event("
1336
+ @"evt);",
1337
+ eventName];
1338
+ } else if (jsonStr && [jsonStr length] > 0) {
1339
+ js = [NSString stringWithFormat:@"javascri"
1340
+ @"pt:"
1341
+ @"cordova."
1342
+ @"fireDocu"
1343
+ @"mentEven"
1344
+ @"t('%@',%"
1345
+ @"@);",
1346
+ eventName, jsonStr];
1347
+ } else {
1348
+ js = [NSString stringWithFormat:@"javascri"
1349
+ @"pt:"
1350
+ @"cordova."
1351
+ @"fireDocu"
1352
+ @"mentEven"
1353
+ @"t('%@')"
1354
+ @";",
1355
+ eventName];
1356
+ }
1357
+ [self.commandDelegate evalJs:js];
2119
1358
  }
2120
1359
 
2121
- - (NSString *)__md5:
2122
- (NSString *)string
2123
- {
2124
- CC_MD5_CTX
2125
- md5Context;
2126
- CC_MD5_Init (
2127
- &md5Context);
2128
- NSData *data = [string
2129
- dataUsingEncoding:
2130
- NSUTF8StringEncoding];
2131
- CC_MD5_Update (
2132
- &md5Context,
2133
- [data bytes],
2134
- (CC_LONG)
2135
- [data
2136
- length]);
2137
- unsigned char digest
2138
- [CC_MD5_DIGEST_LENGTH];
2139
- CC_MD5_Final (
2140
- digest,
2141
- &md5Context);
2142
-
2143
- NSMutableString
2144
- *hexString
2145
- = [NSMutableString
2146
- stringWithCapacity:
2147
- (CC_MD5_DIGEST_LENGTH
2148
- * 2)];
2149
- for (
2150
- int i = 0;
2151
- i
2152
- < CC_MD5_DIGEST_LENGTH;
2153
- i++)
2154
- {
2155
- [hexString
2156
- appendFormat:
2157
- @"%02x",
2158
- digest[i]];
2159
- }
2160
-
2161
- return hexString;
1360
+ - (NSString *)__getAdMobDeviceId {
1361
+ NSUUID *adid = [[ASIdentifierManager sharedManager] advertisingIdentifier];
1362
+ return [self __md5:adid.UUIDString];
2162
1363
  }
2163
1364
 
2164
- #pragma mark \
2165
- GADBannerViewDelegate implementation
2166
- - (void)
2167
- bannerViewDidReceiveAd:
2168
- (GADBannerView
2169
- *)
2170
- bannerView
2171
- {
2172
- [self
2173
- fireEvent:@""
2174
- event:
2175
- @"on."
2176
- @"banner"
2177
- @".load"
2178
- withData:nil];
2179
- NSLog (
2180
- @"bannerViewDidR"
2181
- @"eceiveAd");
2182
- if (auto_Show)
2183
- {
2184
- if (self.bannerView)
2185
- {
2186
- [self
2187
- addBannerViewToView:
2188
- command];
2189
- self.bannerView
2190
- .hidden
2191
- = NO;
1365
+ - (NSString *)__md5:(NSString *)string {
1366
+ CC_MD5_CTX
1367
+ md5Context;
1368
+ CC_MD5_Init(&md5Context);
1369
+ NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
1370
+ CC_MD5_Update(&md5Context, [data bytes], (CC_LONG)[data length]);
1371
+ unsigned char digest[CC_MD5_DIGEST_LENGTH];
1372
+ CC_MD5_Final(digest, &md5Context);
1373
+
1374
+ NSMutableString *hexString =
1375
+ [NSMutableString stringWithCapacity:(CC_MD5_DIGEST_LENGTH * 2)];
1376
+ for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
1377
+ [hexString appendFormat:@"%02x", digest[i]];
2192
1378
  }
2193
- }
2194
- else
2195
- {
2196
- [self
2197
- fireEvent:@""
2198
- event:
2199
- @"on."
2200
- @"bann"
2201
- @"er."
2202
- @"fail"
2203
- @"ed."
2204
- @"show"
2205
- withData:nil];
2206
- }
1379
+
1380
+ return hexString;
2207
1381
  }
2208
- - (void)bannerView:
2209
- (GADBannerView
2210
- *)
2211
- bannerView
2212
- didFailToReceiveAdWithError:
2213
- (NSError *)
2214
- error
2215
- {
2216
- [self
2217
- fireEvent:@""
2218
- event:
2219
- @"on."
2220
- @"banner"
2221
- @".faile"
2222
- @"d.load"
2223
- withData:nil];
2224
- NSLog (
2225
- @"bannerView:"
2226
- @"didFailToRecei"
2227
- @"veAdWithError:"
2228
- @" %@",
2229
- [error
2230
- localizedDescription]);
1382
+
1383
+ #pragma mark GADBannerViewDelegate implementation
1384
+ - (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
1385
+
1386
+ NSString *collapsibleStatus = bannerView.isCollapsible ? @"collapsible" : @"not collapsible";
1387
+ NSDictionary *eventData = @{ @"collapsible": collapsibleStatus };
1388
+ NSError *error;
1389
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:eventData options:0 error:&error];
1390
+
1391
+ if (!jsonData) {
1392
+ NSLog(@"Failed to serialize event data: %@", error);
1393
+ } else {
1394
+ NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
1395
+ [self fireEvent:@"" event:@"on.is.collapsible" withData:jsonString];
1396
+ }
1397
+
1398
+ [self fireEvent:@""
1399
+ event:@"on."
1400
+ @"banner"
1401
+ @".load"
1402
+ withData:nil];
1403
+ NSLog(@"bannerViewDidR"
1404
+ @"eceiveAd");
1405
+ if (auto_Show) {
1406
+ if (self.bannerView) {
1407
+ [self addBannerViewToView:command];
1408
+ self.bannerView.hidden = NO;
1409
+ }
1410
+ } else {
1411
+ [self fireEvent:@""
1412
+ event:@"on."
1413
+ @"bann"
1414
+ @"er."
1415
+ @"fail"
1416
+ @"ed."
1417
+ @"show"
1418
+ withData:nil];
1419
+ }
2231
1420
  }
2232
- - (void)
2233
- bannerViewDidRecordImpression:
2234
- (GADBannerView
2235
- *)
2236
- bannerView
2237
- {
2238
- [self
2239
- fireEvent:@""
2240
- event:
2241
- @"on."
2242
- @"banner"
2243
- @".impre"
2244
- @"ssion"
2245
- withData:nil];
2246
- NSLog (@"bannerViewD"
2247
- @"idRecordImp"
2248
- @"ression");
1421
+ - (void)bannerView:(GADBannerView *)bannerView
1422
+ didFailToReceiveAdWithError:(NSError *)error {
1423
+ [self fireEvent:@""
1424
+ event:@"on."
1425
+ @"banner"
1426
+ @".faile"
1427
+ @"d.load"
1428
+ withData:nil];
1429
+ NSLog(@"bannerView:"
1430
+ @"didFailToRecei"
1431
+ @"veAdWithError:"
1432
+ @" %@",
1433
+ [error localizedDescription]);
2249
1434
  }
2250
- - (void)
2251
- bannerViewWillPresentScreen:
2252
- (GADBannerView
2253
- *)
2254
- bannerView
2255
- {
2256
- [self
2257
- fireEvent:@""
2258
- event:
2259
- @"on."
2260
- @"banner"
2261
- @".open"
2262
- withData:nil];
2263
- NSLog (@"bannerViewW"
2264
- @"illPresentS"
2265
- @"creen");
1435
+ - (void)bannerViewDidRecordImpression:(GADBannerView *)bannerView {
1436
+ [self fireEvent:@""
1437
+ event:@"on."
1438
+ @"banner"
1439
+ @".impre"
1440
+ @"ssion"
1441
+ withData:nil];
1442
+ NSLog(@"bannerViewD"
1443
+ @"idRecordImp"
1444
+ @"ression");
2266
1445
  }
2267
- - (void)
2268
- bannerViewWillDismissScreen:
2269
- (GADBannerView
2270
- *)
2271
- bannerView
2272
- {
2273
- [self
2274
- fireEvent:@""
2275
- event:
2276
- @"on."
2277
- @"banner"
2278
- @".close"
2279
- withData:nil];
2280
- NSLog (@"bannerViewW"
2281
- @"illDismissS"
2282
- @"creen");
1446
+ - (void)bannerViewWillPresentScreen:(GADBannerView *)bannerView {
1447
+ [self fireEvent:@""
1448
+ event:@"on."
1449
+ @"banner"
1450
+ @".open"
1451
+ withData:nil];
1452
+ NSLog(@"bannerViewW"
1453
+ @"illPresentS"
1454
+ @"creen");
2283
1455
  }
2284
- - (void)
2285
- bannerViewDidDismissScreen:
2286
- (GADBannerView
2287
- *)
2288
- bannerView
2289
- {
2290
- [self
2291
- fireEvent:@""
2292
- event:
2293
- @"on."
2294
- @"banner"
2295
- @".did."
2296
- @"dismis"
2297
- @"s"
2298
- withData:nil];
2299
- NSLog (
2300
- @"bannerViewDidD"
2301
- @"ismissScreen");
1456
+ - (void)bannerViewWillDismissScreen:(GADBannerView *)bannerView {
1457
+ [self fireEvent:@""
1458
+ event:@"on."
1459
+ @"banner"
1460
+ @".close"
1461
+ withData:nil];
1462
+ NSLog(@"bannerViewW"
1463
+ @"illDismissS"
1464
+ @"creen");
2302
1465
  }
2303
- #pragma GADFullScreeContentDelegate \
2304
- implementation
2305
- - (void)
2306
- adWillPresentFullScreenContent:
2307
- (id)ad
2308
- {
2309
- if (adFormat == 1)
2310
- {
2311
- [self
2312
- fireEvent:@""
2313
- event:
2314
- @"on."
2315
- @"appO"
2316
- @"penA"
2317
- @"d."
2318
- @"show"
2319
- withData:nil];
2320
- NSLog (
2321
- @"Ad will "
2322
- @"present "
2323
- @"full screen "
2324
- @"content App "
2325
- @"Open Ad.");
2326
- }
2327
- else if (adFormat
2328
- == 2)
2329
- {
2330
- [self
2331
- fireEvent:@""
2332
- event:
2333
- @"on."
2334
- @"inte"
2335
- @"rsti"
2336
- @"tial"
2337
- @".sho"
2338
- @"w"
2339
- withData:nil];
2340
- [self
2341
- fireEvent:@""
2342
- event:
2343
- @"onPr"
2344
- @"esen"
2345
- @"tAd"
2346
- withData:nil];
2347
- NSLog (
2348
- @"Ad will "
2349
- @"present "
2350
- @"full screen "
2351
- @"content "
2352
- @"interstitial"
2353
- @".");
2354
- }
2355
- else if (adFormat
2356
- == 3)
2357
- {
2358
- [self
2359
- fireEvent:@""
2360
- event:
2361
- @"on."
2362
- @"rewa"
2363
- @"rded"
2364
- @".sho"
2365
- @"w"
2366
- withData:nil];
2367
- isAdSkip = 1;
2368
- NSLog (
2369
- @"Ad will "
2370
- @"present "
2371
- @"full screen "
2372
- @"content "
2373
- @"rewarded.");
2374
- }
2375
- else if (adFormat
2376
- == 4)
2377
- {
2378
- isAdSkip = 1;
2379
- [self
2380
- fireEvent:@""
2381
- event:
2382
- @"on."
2383
- @"rewa"
2384
- @"rded"
2385
- @"Int."
2386
- @"show"
2387
- @"ed"
2388
- withData:nil];
2389
- NSLog (
2390
- @"Ad will "
2391
- @"present "
2392
- @"full screen "
2393
- @"content "
2394
- @"interstitial"
2395
- @" rewarded.");
2396
- }
1466
+ - (void)bannerViewDidDismissScreen:(GADBannerView *)bannerView {
1467
+ [self fireEvent:@""
1468
+ event:@"on."
1469
+ @"banner"
1470
+ @".did."
1471
+ @"dismis"
1472
+ @"s"
1473
+ withData:nil];
1474
+ NSLog(@"bannerViewDidD"
1475
+ @"ismissScreen");
2397
1476
  }
2398
- - (void)ad:(id)ad
2399
- didFailToPresentFullScreenContentWithError:
2400
- (NSError *)
2401
- error
2402
- {
2403
- if (adFormat == 1)
2404
- {
2405
- [self
2406
- fireEvent:@""
2407
- event:
2408
- @"on."
2409
- @"appO"
2410
- @"penA"
2411
- @"d."
2412
- @"fail"
2413
- @"ed."
2414
- @"load"
2415
- @"ed"
2416
- withData:nil];
2417
- NSLog (
2418
- @"Ad failed "
2419
- @"to present "
2420
- @"full screen "
2421
- @"content "
2422
- @"with error "
2423
- @"App Open Ad "
2424
- @"%@.",
2425
- [error
2426
- localizedDescription]);
2427
- }
2428
- else if (adFormat
2429
- == 2)
2430
- {
2431
- [self
2432
- fireEvent:@""
2433
- event:
2434
- @"on."
2435
- @"inte"
2436
- @"rsti"
2437
- @"tial"
2438
- @".fai"
2439
- @"led."
2440
- @"load"
2441
- withData:nil];
2442
- NSLog (
2443
- @"Ad failed "
2444
- @"to present "
2445
- @"full screen "
2446
- @"content "
2447
- @"with error "
2448
- @"interstitial"
2449
- @" %@.",
2450
- [error
2451
- localizedDescription]);
2452
- }
2453
- else if (adFormat
2454
- == 3)
2455
- {
2456
- [self
2457
- fireEvent:@""
2458
- event:
2459
- @"on."
2460
- @"rewa"
2461
- @"rded"
2462
- @".fai"
2463
- @"led."
2464
- @"load"
2465
- withData:nil];
2466
- NSLog (
2467
- @"Ad failed "
2468
- @"to present "
2469
- @"full screen "
2470
- @"content "
2471
- @"with error "
2472
- @"rewarded "
2473
- @"%@.",
2474
- [error
2475
- localizedDescription]);
2476
- }
2477
- else if (adFormat
2478
- == 4)
2479
- {
2480
- [self
2481
- fireEvent:@""
2482
- event:
2483
- @"on."
2484
- @"rewa"
2485
- @"rded"
2486
- @"Int."
2487
- @"fail"
2488
- @"ed."
2489
- @"load"
2490
- withData:nil];
2491
- NSLog (
2492
- @"Ad failed "
2493
- @"to present "
2494
- @"full screen "
2495
- @"content "
2496
- @"with error "
2497
- @"interstitial"
2498
- @" "
2499
- @"rewarded "
2500
- @"%@.",
2501
- [error
2502
- localizedDescription]);
2503
- }
1477
+ #pragma GADFullScreeContentDelegate implementation
1478
+ - (void)adWillPresentFullScreenContent:(id)ad {
1479
+ if (adFormat == 1) {
1480
+ [self fireEvent:@""
1481
+ event:@"on."
1482
+ @"appO"
1483
+ @"penA"
1484
+ @"d."
1485
+ @"show"
1486
+ withData:nil];
1487
+ NSLog(@"Ad will "
1488
+ @"present "
1489
+ @"full screen "
1490
+ @"content App "
1491
+ @"Open Ad.");
1492
+ } else if (adFormat == 2) {
1493
+ [self fireEvent:@""
1494
+ event:@"on."
1495
+ @"inte"
1496
+ @"rsti"
1497
+ @"tial"
1498
+ @".sho"
1499
+ @"w"
1500
+ withData:nil];
1501
+ [self fireEvent:@""
1502
+ event:@"onPr"
1503
+ @"esen"
1504
+ @"tAd"
1505
+ withData:nil];
1506
+ NSLog(@"Ad will "
1507
+ @"present "
1508
+ @"full screen "
1509
+ @"content "
1510
+ @"interstitial"
1511
+ @".");
1512
+ } else if (adFormat == 3) {
1513
+ [self fireEvent:@""
1514
+ event:@"on."
1515
+ @"rewa"
1516
+ @"rded"
1517
+ @".sho"
1518
+ @"w"
1519
+ withData:nil];
1520
+ isAdSkip = 1;
1521
+ NSLog(@"Ad will "
1522
+ @"present "
1523
+ @"full screen "
1524
+ @"content "
1525
+ @"rewarded.");
1526
+ } else if (adFormat == 4) {
1527
+ isAdSkip = 1;
1528
+ [self fireEvent:@""
1529
+ event:@"on."
1530
+ @"rewa"
1531
+ @"rded"
1532
+ @"Int."
1533
+ @"show"
1534
+ @"ed"
1535
+ withData:nil];
1536
+ NSLog(@"Ad will "
1537
+ @"present "
1538
+ @"full screen "
1539
+ @"content "
1540
+ @"interstitial"
1541
+ @" rewarded.");
1542
+ }
2504
1543
  }
2505
- - (void)
2506
- adDidDismissFullScreenContent:
2507
- (id)ad
2508
- {
2509
- if (adFormat == 1)
2510
- {
2511
- [self
2512
- fireEvent:@""
2513
- event:
2514
- @"on."
2515
- @"appO"
2516
- @"penA"
2517
- @"d."
2518
- @"dism"
2519
- @"isse"
2520
- @"d"
2521
- withData:nil];
2522
- NSLog (
2523
- @"Ad did "
2524
- @"dismiss "
2525
- @"full screen "
2526
- @"content App "
2527
- @"Open Ad.");
2528
- }
2529
- else if (adFormat
2530
- == 2)
2531
- {
2532
- [self
2533
- fireEvent:@""
2534
- event:
2535
- @"on."
2536
- @"inte"
2537
- @"rsti"
2538
- @"tial"
2539
- @".dis"
2540
- @"miss"
2541
- @"ed"
2542
- withData:nil];
2543
- NSLog (
2544
- @"Ad did "
2545
- @"dismiss "
2546
- @"full screen "
2547
- @"content "
2548
- @"interstitial"
2549
- @".");
2550
- }
2551
- else if (adFormat
2552
- == 3)
2553
- {
2554
- [self
2555
- fireEvent:@""
2556
- event:
2557
- @"on."
2558
- @"rewa"
2559
- @"rded"
2560
- @".dis"
2561
- @"miss"
2562
- @"ed"
2563
- withData:nil];
2564
- if (isAdSkip != 2)
2565
- {
2566
- [self
2567
- fireEvent:@""
2568
- event:
2569
- @"on"
2570
- @".r"
2571
- @"ew"
2572
- @"ar"
2573
- @"de"
2574
- @"d."
2575
- @"ad"
2576
- @".s"
2577
- @"ki"
2578
- @"p"
2579
- withData:
2580
- nil];
1544
+ - (void)ad:(id)ad didFailToPresentFullScreenContentWithError:(NSError *)error {
1545
+ if (adFormat == 1) {
1546
+ [self fireEvent:@""
1547
+ event:@"on."
1548
+ @"appO"
1549
+ @"penA"
1550
+ @"d."
1551
+ @"fail"
1552
+ @"ed."
1553
+ @"load"
1554
+ @"ed"
1555
+ withData:nil];
1556
+ NSLog(@"Ad failed "
1557
+ @"to present "
1558
+ @"full screen "
1559
+ @"content "
1560
+ @"with error "
1561
+ @"App Open Ad "
1562
+ @"%@.",
1563
+ [error localizedDescription]);
1564
+ } else if (adFormat == 2) {
1565
+ [self fireEvent:@""
1566
+ event:@"on."
1567
+ @"inte"
1568
+ @"rsti"
1569
+ @"tial"
1570
+ @".fai"
1571
+ @"led."
1572
+ @"load"
1573
+ withData:nil];
1574
+ NSLog(@"Ad failed "
1575
+ @"to present "
1576
+ @"full screen "
1577
+ @"content "
1578
+ @"with error "
1579
+ @"interstitial"
1580
+ @" %@.",
1581
+ [error localizedDescription]);
1582
+ } else if (adFormat == 3) {
1583
+ [self fireEvent:@""
1584
+ event:@"on."
1585
+ @"rewa"
1586
+ @"rded"
1587
+ @".fai"
1588
+ @"led."
1589
+ @"load"
1590
+ withData:nil];
1591
+ NSLog(@"Ad failed "
1592
+ @"to present "
1593
+ @"full screen "
1594
+ @"content "
1595
+ @"with error "
1596
+ @"rewarded "
1597
+ @"%@.",
1598
+ [error localizedDescription]);
1599
+ } else if (adFormat == 4) {
1600
+ [self fireEvent:@""
1601
+ event:@"on."
1602
+ @"rewa"
1603
+ @"rded"
1604
+ @"Int."
1605
+ @"fail"
1606
+ @"ed."
1607
+ @"load"
1608
+ withData:nil];
1609
+ NSLog(@"Ad failed "
1610
+ @"to present "
1611
+ @"full screen "
1612
+ @"content "
1613
+ @"with error "
1614
+ @"interstitial"
1615
+ @" "
1616
+ @"rewarded "
1617
+ @"%@.",
1618
+ [error localizedDescription]);
2581
1619
  }
2582
- NSLog (
2583
- @"Ad did "
2584
- @"dismiss "
2585
- @"full screen "
2586
- @"content "
2587
- @"rewarded.");
2588
- }
2589
- else if (adFormat
2590
- == 4)
2591
- {
2592
- if (isAdSkip != 2)
2593
- {
2594
- [self
2595
- fireEvent:@""
2596
- event:
2597
- @"on"
2598
- @".r"
2599
- @"ew"
2600
- @"ar"
2601
- @"de"
2602
- @"dI"
2603
- @"nt"
2604
- @".a"
2605
- @"d."
2606
- @"sk"
2607
- @"ip"
2608
- withData:
2609
- nil];
1620
+ }
1621
+
1622
+ - (void)adDidDismissFullScreenContent:(id)ad {
1623
+ if (adFormat == 1) {
1624
+ [self fireEvent:@""
1625
+ event:@"on."
1626
+ @"appO"
1627
+ @"penA"
1628
+ @"d."
1629
+ @"dism"
1630
+ @"isse"
1631
+ @"d"
1632
+ withData:nil];
1633
+ NSLog(@"Ad did "
1634
+ @"dismiss "
1635
+ @"full screen "
1636
+ @"content App "
1637
+ @"Open Ad.");
1638
+ } else if (adFormat == 2) {
1639
+ [self fireEvent:@""
1640
+ event:@"on."
1641
+ @"inte"
1642
+ @"rsti"
1643
+ @"tial"
1644
+ @".dis"
1645
+ @"miss"
1646
+ @"ed"
1647
+ withData:nil];
1648
+ NSLog(@"Ad did "
1649
+ @"dismiss "
1650
+ @"full screen "
1651
+ @"content "
1652
+ @"interstitial"
1653
+ @".");
1654
+ } else if (adFormat == 3) {
1655
+ [self fireEvent:@""
1656
+ event:@"on."
1657
+ @"rewa"
1658
+ @"rded"
1659
+ @".dis"
1660
+ @"miss"
1661
+ @"ed"
1662
+ withData:nil];
1663
+ if (isAdSkip != 2) {
1664
+ [self fireEvent:@""
1665
+ event:@"on"
1666
+ @".r"
1667
+ @"ew"
1668
+ @"ar"
1669
+ @"de"
1670
+ @"d."
1671
+ @"ad"
1672
+ @".s"
1673
+ @"ki"
1674
+ @"p"
1675
+ withData:nil];
1676
+ }
1677
+ NSLog(@"Ad did "
1678
+ @"dismiss "
1679
+ @"full screen "
1680
+ @"content "
1681
+ @"rewarded.");
1682
+ } else if (adFormat == 4) {
1683
+ if (isAdSkip != 2) {
1684
+ [self fireEvent:@""
1685
+ event:@"on"
1686
+ @".r"
1687
+ @"ew"
1688
+ @"ar"
1689
+ @"de"
1690
+ @"dI"
1691
+ @"nt"
1692
+ @".a"
1693
+ @"d."
1694
+ @"sk"
1695
+ @"ip"
1696
+ withData:nil];
1697
+ }
1698
+ [self fireEvent:@""
1699
+ event:@"on."
1700
+ @"rewa"
1701
+ @"rded"
1702
+ @"Int."
1703
+ @"dism"
1704
+ @"isse"
1705
+ @"d"
1706
+ withData:nil];
1707
+ NSLog(@"Ad did "
1708
+ @"dismiss "
1709
+ @"full screen "
1710
+ @"content "
1711
+ @"interstitial"
1712
+ @" rewarded.");
2610
1713
  }
2611
- [self
2612
- fireEvent:@""
2613
- event:
2614
- @"on."
2615
- @"rewa"
2616
- @"rded"
2617
- @"Int."
2618
- @"dism"
2619
- @"isse"
2620
- @"d"
2621
- withData:nil];
2622
- NSLog (
2623
- @"Ad did "
2624
- @"dismiss "
2625
- @"full screen "
2626
- @"content "
2627
- @"interstitial"
2628
- @" rewarded.");
2629
- }
2630
1714
  }
2631
1715
  #pragma mark Cleanup
2632
1716
  - (void)dealloc
2633
1717
  {
2634
- self.appOpenAd = nil;
2635
- self.bannerView
2636
- = nil;
2637
- self.interstitial
2638
- = nil;
2639
- self.rewardedAd
2640
- = nil;
2641
- self.rewardedInterstitialAd
2642
- = nil;
1718
+ self.appOpenAd = nil;
1719
+ self.bannerView
1720
+ = nil;
1721
+ self.interstitial
1722
+ = nil;
1723
+ self.rewardedAd
1724
+ = nil;
1725
+ self.rewardedInterstitialAd
1726
+ = nil;
1727
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
2643
1728
  }
2644
1729
  @end
1730
+