emi-indo-cordova-plugin-admob 1.3.9 → 1.4.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.
@@ -0,0 +1,554 @@
1
+
2
+ #import "emiAdmobPlugin.h"
3
+ #import <Cordova/CDVPlugin.h>
4
+ #import <UserMessagingPlatform/UserMessagingPlatform.h>
5
+ #import <AppTrackingTransparency/AppTrackingTransparency.h>
6
+ #import <AdSupport/AdSupport.h>
7
+ #import <Foundation/Foundation.h>
8
+ @implementation emiAdmobPlugin
9
+ @synthesize appOpenAd;
10
+ @synthesize bannerView;
11
+ @synthesize interstitial;
12
+ @synthesize rewardedInterstitialAd;
13
+ @synthesize rewardedAd;
14
+ @synthesize isPrivacyOptionsRequired;
15
+ int idfaStatus = 0;
16
+ int fromStatus = 0;
17
+ int adFormat = 0;
18
+ int adWidth = 320;
19
+ BOOL isIAB = NO;
20
+ - (void)pluginInitialize {
21
+ isIAB = YES;
22
+ [[NSUserDefaults standardUserDefaults] synchronize];
23
+ }
24
+ - (void)requestIDFA:(CDVInvokedUrlCommand*)command {
25
+ CDVPluginResult *pluginResult;
26
+ NSString *callbackId = command.callbackId;
27
+ if (@available(iOS 14, *)) {
28
+ [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
29
+ if (status == ATTrackingManagerAuthorizationStatusDenied) {
30
+ idfaStatus = ATTrackingManagerAuthorizationStatusDenied;
31
+ } else if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
32
+ idfaStatus = ATTrackingManagerAuthorizationStatusAuthorized;
33
+ } else if (status == ATTrackingManagerAuthorizationStatusRestricted) {
34
+ idfaStatus = ATTrackingManagerAuthorizationStatusRestricted;
35
+ } else if (status == ATTrackingManagerAuthorizationStatusNotDetermined) {
36
+ idfaStatus = ATTrackingManagerAuthorizationStatusNotDetermined;
37
+ }
38
+ }];
39
+ [self fireEvent:@"" event:@"on.getIDFA" withData:nil];
40
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:idfaStatus];
41
+ } else {
42
+ [self fireEvent:@"" event:@"on.getIDFA.error" withData:nil];
43
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
44
+ }
45
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
46
+ }
47
+ - (void)getConsentRequest:(CDVInvokedUrlCommand*)command {
48
+ CDVPluginResult *pluginResult;
49
+ NSString *callbackId = command.callbackId;
50
+ UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
51
+ // UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
52
+ // debugSettings.testDeviceIdentifiers = @[@"59156CDC-B042-4D81-A9FA-900869782912"];
53
+ // parameters.debugSettings = debugSettings;
54
+ // debugSettings.geography = UMPDebugGeographyEEA;
55
+ BOOL tagForUnderAgeOfConsent = [[command argumentAtIndex:0] boolValue];
56
+ parameters.tagForUnderAgeOfConsent = tagForUnderAgeOfConsent;
57
+ [UMPConsentInformation.sharedInstance
58
+ requestConsentInfoUpdateWithParameters:parameters
59
+ completionHandler:^(NSError *_Nullable requestConsentError) {
60
+ if (requestConsentError) {
61
+ // Consent gathering failed.
62
+ NSLog(@"Error: %@", requestConsentError.localizedDescription);
63
+ return;
64
+ }
65
+ [UMPConsentForm loadAndPresentIfRequiredFromViewController:self.viewController
66
+ completionHandler:^(NSError *loadAndPresentError) {
67
+ if (loadAndPresentError) {
68
+ // Consent gathering failed.
69
+ NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
70
+ return;
71
+ }
72
+ UMPFormStatus formStatus = UMPConsentInformation.sharedInstance.formStatus;
73
+ if (formStatus == UMPFormStatusUnknown) {
74
+ fromStatus = 0;
75
+ } else if (formStatus == UMPFormStatusAvailable) {
76
+ fromStatus = 1;
77
+
78
+ } else if (formStatus == UMPFormStatusUnavailable) {
79
+ fromStatus = 2;
80
+ }
81
+ [self fireEvent:@"" event:@"on.get.from.status" withData:nil];
82
+ }];
83
+
84
+ }];
85
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:fromStatus];
86
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
87
+ }
88
+ - (void)showPrivacyOptionsForm:(CDVInvokedUrlCommand*)command {
89
+ UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
90
+ // UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
91
+ // debugSettings.testDeviceIdentifiers = @[@"59156CDC-B042-4D81-A9FA-900869782912"];
92
+ // parameters.debugSettings = debugSettings;
93
+ // debugSettings.geography = UMPDebugGeographyEEA;
94
+ BOOL tagForUnderAgeOfConsent = [[command argumentAtIndex:0] boolValue];
95
+ parameters.tagForUnderAgeOfConsent = tagForUnderAgeOfConsent;
96
+ [UMPConsentInformation.sharedInstance
97
+ requestConsentInfoUpdateWithParameters:parameters
98
+ completionHandler:^(NSError *_Nullable requestConsentError) {
99
+ // ...
100
+ [UMPConsentForm loadAndPresentIfRequiredFromViewController:self.viewController
101
+ completionHandler:^(NSError *loadAndPresentError) {
102
+ }];
103
+ [self isPrivacyOptionsRequired];
104
+ }];
105
+ [UMPConsentForm presentPrivacyOptionsFormFromViewController:self.viewController completionHandler:^(NSError * _Nullable formError) {
106
+ if (formError) {
107
+ // Handle the error.
108
+ NSLog(@"Error: %@", formError.localizedDescription);
109
+ [self fireEvent:@"" event:@"on.getPrivacyOptionsFrom.error" withData:nil];
110
+ }
111
+ }];
112
+ }
113
+ - (BOOL)isPrivacyOptionsRequired {
114
+ return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus ==
115
+ UMPPrivacyOptionsRequirementStatusRequired;
116
+ }
117
+ - (void)getIabTfc:(CDVInvokedUrlCommand*)command {
118
+ CDVPluginResult *pluginResult;
119
+ NSString *callbackId = command.callbackId;
120
+ if (isIAB == 1) {
121
+ NSMutableDictionary* result = [[NSMutableDictionary alloc] init];
122
+ NSInteger CmpSdkVersion = [NSUserDefaults.standardUserDefaults
123
+ integerForKey:@"IABTCF_CmpSdkVersion"] ?: 2;
124
+ NSString *purposeConsents = [NSUserDefaults.standardUserDefaults
125
+ stringForKey:@"IABTCF_PurposeConsents"] ?: @"";
126
+ NSString *tCString = [NSUserDefaults.standardUserDefaults
127
+ stringForKey:@"IABTCF_TCString"] ?: @"";
128
+ NSInteger gdprApplies = [NSUserDefaults.standardUserDefaults
129
+ integerForKey:@"IABTCF_gdprApplies"] ?: 0;
130
+ [result setObject:[NSNumber numberWithInteger:CmpSdkVersion] forKey:@"IABTCF_CmpSdkVersion"];
131
+ [result setObject:[NSNumber numberWithInteger:gdprApplies] forKey:@"IABTCF_gdprApplies"];
132
+ [result setObject:[NSString stringWithString:purposeConsents] forKey:@"IABTCF_PurposeConsents"];
133
+ [result setObject:[NSString stringWithString:tCString] forKey:@"IABTCF_TCString"];
134
+
135
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
136
+ [self fireEvent:@"" event:@"on.getIabTfc" withData:nil];
137
+ } else {
138
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
139
+ }
140
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
141
+ }
142
+ - (void)consentReset:(CDVInvokedUrlCommand*)command {
143
+ CDVPluginResult *pluginResult;
144
+ NSString *callbackId = command.callbackId;
145
+ @try {
146
+ [UMPConsentInformation.sharedInstance reset];
147
+ }@catch (NSException *exception) {
148
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:exception.reason];
149
+ }
150
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
151
+ }
152
+ - (void)globalSettings:(CDVInvokedUrlCommand*)command {
153
+ CDVPluginResult *pluginResult;
154
+ NSString *callbackId = command.callbackId;
155
+ BOOL setAppMuted = [[command argumentAtIndex:0] boolValue];
156
+ float setAppVolume = [[command argumentAtIndex:1] floatValue];
157
+ @try {
158
+ GADMobileAds.sharedInstance.applicationVolume = setAppVolume;
159
+ GADMobileAds.sharedInstance.applicationMuted = setAppMuted;
160
+ }@catch (NSException *exception) {
161
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:exception.reason];
162
+ }
163
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
164
+ }
165
+ - (void)targeting:(CDVInvokedUrlCommand*)command {
166
+ CDVPluginResult *pluginResult;
167
+ NSString *callbackId = command.callbackId;
168
+ NSNumber *TagForChildDirectedTreatment = [command argumentAtIndex:0];
169
+ NSNumber *tagForUnderAgeOfConsent = [command argumentAtIndex:1];
170
+ NSString *maxAdContentRating = [command argumentAtIndex:2];
171
+ @try {
172
+ GADRequestConfiguration *requestConfiguration = GADMobileAds.sharedInstance.requestConfiguration;
173
+ requestConfiguration.tagForChildDirectedTreatment = TagForChildDirectedTreatment;
174
+ requestConfiguration.tagForUnderAgeOfConsent = tagForUnderAgeOfConsent;
175
+ requestConfiguration.maxAdContentRating = maxAdContentRating;
176
+ }@catch (NSException *exception) {
177
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:exception.reason];
178
+ }
179
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
180
+ }
181
+ - (void)initialize:(CDVInvokedUrlCommand*)command {
182
+ GADMobileAds *ads = [GADMobileAds sharedInstance];
183
+ [ads startWithCompletionHandler:^(GADInitializationStatus *status) {
184
+ // Optional: Log each adapter's initialization latency.
185
+ NSDictionary *adapterStatuses = [status adapterStatusesByClassName];
186
+ for (NSString *adapter in adapterStatuses) {
187
+ GADAdapterStatus *adapterStatus = adapterStatuses[adapter];
188
+ NSLog(@"Adapter Name: %@, Description: %@, Latency: %f", adapter,
189
+ adapterStatus.description, adapterStatus.latency);
190
+ }
191
+ [self fireEvent:@"" event:@"on.sdkInitialization" withData:nil];
192
+ }];
193
+ }
194
+ - (GADAdSize)__AdSizeFromString:(NSString *)size
195
+ {
196
+ if ([size isEqualToString:@"Anchored_adaptive"]) {
197
+ return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(adWidth);
198
+ } else if ([size isEqualToString:@"Inline_adaptive"]) {
199
+ return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(adWidth);
200
+ } else if ([size isEqualToString:@"BANNER"]) {
201
+ return GADAdSizeBanner;
202
+ } else if ([size isEqualToString:@"LARGE_BANNER"]) {
203
+ return GADAdSizeLargeBanner;
204
+ } else if ([size isEqualToString:@"FULL_BANNER"]) {
205
+ return GADAdSizeFullBanner;
206
+ } else if ([size isEqualToString:@"LEADERBOARD"]) {
207
+ return GADAdSizeLeaderboard;
208
+ } else {
209
+ return GADAdSizeBanner;
210
+ }
211
+ }
212
+ - (void)loadBannerAdIOS:(CDVInvokedUrlCommand*)command {
213
+ if(self.bannerView) {
214
+ NSLog(@"Admob banner has been initing");
215
+ return;
216
+ }
217
+ CDVPluginResult *pluginResult;
218
+ NSString *callbackId = command.callbackId;
219
+ adFormat = 3;
220
+ if (adFormat == 3) {
221
+ UIView *parentView = [self.webView superview];
222
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
223
+ NSNumber* x = [command.arguments objectAtIndex:1];
224
+ NSNumber* y = [command.arguments objectAtIndex:2];
225
+ NSString* size = [command.arguments objectAtIndex:3];
226
+ NSNumber* adaptiveWidth = [command.arguments objectAtIndex:4];
227
+ NSString* collapsible = [command.arguments objectAtIndex:5];
228
+ int intValue = [adaptiveWidth intValue];
229
+ adWidth = intValue;
230
+ float posX = [x floatValue];
231
+ float posY = [y floatValue];
232
+ GADAdSize sizes = [self __AdSizeFromString:size];
233
+ CGPoint origin = CGPointMake(posX,posY);
234
+ self.bannerView = [[GADBannerView alloc]
235
+ initWithAdSize:sizes
236
+ origin:origin];
237
+ GADExtras *extras = [[GADExtras alloc] init];
238
+ extras.additionalParameters = @{@"collapsible" : collapsible};
239
+ self.bannerView.adUnitID = adUnitId;
240
+ self.bannerView.rootViewController = self.viewController;
241
+ self.bannerView.delegate = self;
242
+ GADRequest *request = [GADRequest request];
243
+ [self.bannerView loadRequest:request];
244
+ [request registerAdNetworkExtras:extras];
245
+ self.bannerView.hidden = YES;
246
+ [parentView addSubview:self.bannerView];
247
+ [parentView bringSubviewToFront:self.bannerView];
248
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
249
+ } else {
250
+ NSLog(@"Admob Option invalid for banner");
251
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
252
+ }
253
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
254
+ }
255
+ - (void)showBannerAd:(CDVInvokedUrlCommand*)command {
256
+ CDVPluginResult *pluginResult;
257
+ NSString *callbackId = command.callbackId;
258
+ if(self.bannerView) {
259
+ self.bannerView.hidden = NO;
260
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
261
+ } else {
262
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
263
+ }
264
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
265
+ }
266
+ - (void)hiddenAd:(CDVInvokedUrlCommand*)command {
267
+ CDVPluginResult *pluginResult;
268
+ NSString *callbackId = command.callbackId;
269
+ if(self.bannerView) {
270
+ self.bannerView.hidden = YES;
271
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
272
+ } else {
273
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
274
+ }
275
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
276
+ }
277
+
278
+ - (void)removeBannerAd:(CDVInvokedUrlCommand*)command {
279
+ CDVPluginResult *pluginResult;
280
+ NSString *callbackId = command.callbackId;
281
+ if(self.bannerView) {
282
+ self.bannerView.hidden = YES;
283
+ [self.bannerView removeFromSuperview];
284
+ self.bannerView = nil;
285
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
286
+ } else {
287
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
288
+ }
289
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
290
+ }
291
+ - (void)loadAppOpenAd:(CDVInvokedUrlCommand *)command {
292
+ CDVPluginResult *pluginResult;
293
+ NSString *callbackId = command.callbackId;
294
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
295
+ adFormat = 1;
296
+ self.appOpenAd = nil;
297
+ if (adFormat == 1){
298
+ [GADAppOpenAd loadWithAdUnitID:adUnitId
299
+ request:[GADRequest request]
300
+ orientation:UIInterfaceOrientationPortrait
301
+ completionHandler:^(GADAppOpenAd *ad, NSError *error) {
302
+ if (error) {
303
+ [self fireEvent:@"" event:@"on.appOpenAd.failed.loaded" withData:nil];
304
+ NSLog(@"Failed to load App Open Ad ad with error: %@", [error localizedDescription]);
305
+ return;
306
+ }
307
+ self.appOpenAd = ad;
308
+ self.appOpenAd.fullScreenContentDelegate = self;
309
+ [self fireEvent:@"" event:@"on.appOpenAd.loaded" withData:nil];
310
+ }];
311
+ }
312
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
313
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
314
+ }
315
+ - (void)showAppOpenAd:(CDVInvokedUrlCommand *)command {
316
+ CDVPluginResult *pluginResult;
317
+ NSString *callbackId = command.callbackId;
318
+ if (self.appOpenAd && [self.appOpenAd
319
+ canPresentFromRootViewController:self.viewController
320
+ error:nil]) { [self.appOpenAd presentFromRootViewController:self.viewController];
321
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
322
+ } else {
323
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
324
+ [self fireEvent:@"" event:@"on.appOpenAd.failed.show" withData:nil];
325
+ }
326
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
327
+ }
328
+ - (void)loadInterstitialAd:(CDVInvokedUrlCommand *)command {
329
+ CDVPluginResult *pluginResult;
330
+ NSString *callbackId = command.callbackId;
331
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
332
+ adFormat = 2;
333
+ if (adFormat == 2){
334
+ GADRequest *request = [GADRequest request];
335
+ [GADInterstitialAd
336
+ loadWithAdUnitID:adUnitId
337
+ request:request
338
+ completionHandler:^(GADInterstitialAd *ad, NSError *error) {
339
+ if (error) {
340
+ NSLog(@"Failed to load interstitial ad with error: %@", [error localizedDescription]);
341
+ return;
342
+ }
343
+ self.interstitial = ad;
344
+ self.interstitial.fullScreenContentDelegate = self;
345
+ [self fireEvent:@"" event:@"on.interstitial.loaded" withData:nil];
346
+ }];
347
+ }
348
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
349
+
350
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
351
+ }
352
+ - (void)showInterstitialAd:(CDVInvokedUrlCommand *)command {
353
+ CDVPluginResult *pluginResult;
354
+ NSString *callbackId = command.callbackId;
355
+ if (self.interstitial && [self.interstitial
356
+ canPresentFromRootViewController:self.viewController error:nil]) {
357
+
358
+ [self.interstitial presentFromRootViewController:self.viewController];
359
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
360
+ } else {
361
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
362
+ [self fireEvent:@"" event:@"on.interstitial.failed.show" withData:nil];
363
+ }
364
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
365
+ }
366
+ - (void)loadRewardedInterstitialAd:(CDVInvokedUrlCommand*)command {
367
+ CDVPluginResult *pluginResult;
368
+ NSString *callbackId = command.callbackId;
369
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
370
+ adFormat = 4;
371
+ if (adFormat == 4){
372
+ GADRequest *request = [GADRequest request];
373
+ [GADRewardedInterstitialAd
374
+ loadWithAdUnitID:adUnitId
375
+ request:request
376
+ completionHandler:^(GADRewardedInterstitialAd *ad, NSError *error) {
377
+ if (error) {
378
+ NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
379
+ return;
380
+ }
381
+ self.rewardedInterstitialAd = ad;
382
+ NSLog(@"Rewarded ad loaded.");
383
+ self.rewardedInterstitialAd.fullScreenContentDelegate = self;
384
+ [self fireEvent:@"" event:@"on.rewardedInt.loaded" withData:nil];
385
+ }];
386
+ }
387
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
388
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
389
+ }
390
+ -(void)showRewardedInterstitialAd:(CDVInvokedUrlCommand *)command {
391
+ CDVPluginResult *pluginResult;
392
+ NSString *callbackId = command.callbackId;
393
+ if (self.rewardedInterstitialAd && [self.rewardedInterstitialAd canPresentFromRootViewController:self.viewController error:nil]) {
394
+
395
+ [self.rewardedInterstitialAd presentFromRootViewController:self.viewController
396
+ userDidEarnRewardHandler:^{
397
+ GADAdReward *reward =
398
+ self.rewardedInterstitialAd.adReward;
399
+ [self fireEvent:@"" event:@"on.rewardedInt.userEarnedReward" withData:nil];
400
+
401
+ NSString *rewardMessage = [NSString stringWithFormat:@"Reward received with "
402
+ @"currency %@ , amount %ld",
403
+ reward.type, [reward.amount longValue]];
404
+ NSLog(@"%@", rewardMessage);
405
+
406
+ }];
407
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
408
+ } else {
409
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
410
+ [self fireEvent:@"" event:@"on.rewardedInt.failed.show" withData:nil];
411
+ }
412
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
413
+ }
414
+ - (void)loadRewardedAd:(CDVInvokedUrlCommand*)command {
415
+
416
+ CDVPluginResult *pluginResult;
417
+ NSString *callbackId = command.callbackId;
418
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
419
+ adFormat = 3;
420
+ if (adFormat == 3){
421
+ GADRequest *request = [GADRequest request];
422
+ [GADRewardedAd
423
+ loadWithAdUnitID:adUnitId
424
+ request:request
425
+ completionHandler:^(GADRewardedAd *ad, NSError *error) {
426
+ if (error) {
427
+ NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
428
+ return;
429
+ }
430
+ self.rewardedAd = ad;
431
+ NSLog(@"Rewarded ad loaded.");
432
+ self.rewardedAd.fullScreenContentDelegate = self;
433
+ [self fireEvent:@"" event:@"on.rewarded.loaded" withData:nil];
434
+ }];
435
+ }
436
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
437
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
438
+ }
439
+ -(void)showRewardedAd:(CDVInvokedUrlCommand *)command {
440
+ CDVPluginResult *pluginResult;
441
+ NSString *callbackId = command.callbackId;
442
+ if (self.rewardedAd && [self.rewardedAd canPresentFromRootViewController:self.viewController error:nil]) {
443
+
444
+ [self.rewardedAd presentFromRootViewController:self.viewController
445
+ userDidEarnRewardHandler:^{
446
+ GADAdReward *reward =
447
+ self.rewardedAd.adReward;
448
+ [self fireEvent:@"" event:@"on.reward.userEarnedReward" withData:nil];
449
+
450
+ NSString *rewardMessage = [NSString stringWithFormat:@"Reward received with currency %@ , amount %lf", reward.type, [reward.amount doubleValue]];
451
+ NSLog(@"%@", rewardMessage);
452
+
453
+ }];
454
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
455
+ } else {
456
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
457
+ [self fireEvent:@"" event:@"on.rewarded.failed.show" withData:nil];
458
+ }
459
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
460
+ }
461
+ - (void) fireEvent:(NSString *)obj event:(NSString *)eventName withData:(NSString *)jsonStr {
462
+ NSString* js;
463
+ if(obj && [obj isEqualToString:@"window"]) {
464
+ js = [NSString stringWithFormat:@"var evt=document.createEvent(\"UIEvents\");evt.initUIEvent(\"%@\",true,false,window,0);window.dispatchEvent(evt);", eventName];
465
+ } else if(jsonStr && [jsonStr length]>0) {
466
+ js = [NSString stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@',%@);", eventName, jsonStr];
467
+ } else {
468
+ js = [NSString stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@');", eventName];
469
+ }
470
+ [self.commandDelegate evalJs:js];
471
+ }
472
+ #pragma mark GADBannerViewDelegate implementation
473
+ - (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
474
+ [self fireEvent:@"" event:@"on.banner.load" withData:nil];
475
+ NSLog(@"bannerViewDidReceiveAd");
476
+ }
477
+ - (void)bannerView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error {
478
+ [self fireEvent:@"" event:@"on.banner.failed.load" withData:nil];
479
+ NSLog(@"bannerView:didFailToReceiveAdWithError: %@", [error localizedDescription]);
480
+ }
481
+ - (void)bannerViewDidRecordImpression:(GADBannerView *)bannerView {
482
+ [self fireEvent:@"" event:@"on.banner.impression" withData:nil];
483
+ NSLog(@"bannerViewDidRecordImpression");
484
+ }
485
+ - (void)bannerViewWillPresentScreen:(GADBannerView *)bannerView {
486
+ [self fireEvent:@"" event:@"on.banner.open" withData:nil];
487
+ NSLog(@"bannerViewWillPresentScreen");
488
+ }
489
+ - (void)bannerViewWillDismissScreen:(GADBannerView *)bannerView {
490
+ [self fireEvent:@"" event:@"on.banner.close" withData:nil];
491
+ NSLog(@"bannerViewWillDismissScreen");
492
+ }
493
+ - (void)bannerViewDidDismissScreen:(GADBannerView *)bannerView {
494
+ [self fireEvent:@"" event:@"on.banner.did.dismiss" withData:nil];
495
+ NSLog(@"bannerViewDidDismissScreen");
496
+ }
497
+ #pragma GADFullScreeContentDelegate implementation
498
+ - (void)adWillPresentFullScreenContent:(id)ad {
499
+ if (adFormat == 1){
500
+ [self fireEvent:@"" event:@"on.appOpenAd.show" withData:nil];
501
+ NSLog(@"Ad will present full screen content App Open Ad.");
502
+ } else if (adFormat == 2){
503
+
504
+ [self fireEvent:@"" event:@"on.interstitial.show" withData:nil];
505
+ [self fireEvent:@"" event:@"onPresentAd" withData:nil];
506
+ NSLog(@"Ad will present full screen content interstitial.");
507
+ } else if (adFormat == 3) {
508
+ [self fireEvent:@"" event:@"on.rewarded.show" withData:nil];
509
+ NSLog(@"Ad will present full screen content rewarded.");
510
+ } else if (adFormat == 4) {
511
+ [self fireEvent:@"" event:@"on.rewardedInt.showed" withData:nil];
512
+ NSLog(@"Ad will present full screen content interstitial rewarded.");
513
+ }
514
+ }
515
+ - (void)ad:(id)ad didFailToPresentFullScreenContentWithError:(NSError *)error {
516
+ if (adFormat == 1){
517
+ [self fireEvent:@"" event:@"on.appOpenAd.failed.loaded" withData:nil];
518
+ NSLog(@"Ad failed to present full screen content with error App Open Ad %@.", [error localizedDescription]);
519
+ } else if (adFormat == 2){
520
+ [self fireEvent:@"" event:@"on.interstitial.failed.load" withData:nil];
521
+ NSLog(@"Ad failed to present full screen content with error interstitial %@.", [error localizedDescription]);
522
+ } else if (adFormat == 3) {
523
+ [self fireEvent:@"" event:@"on.rewarded.failed.load" withData:nil];
524
+ NSLog(@"Ad failed to present full screen content with error rewarded %@.", [error localizedDescription]);
525
+ } else if (adFormat == 4) {
526
+ [self fireEvent:@"" event:@"on.rewardedInt.failed.load" withData:nil];
527
+ NSLog(@"Ad failed to present full screen content with error interstitial rewarded %@.", [error localizedDescription]);
528
+ }
529
+ }
530
+ - (void)adDidDismissFullScreenContent:(id)ad {
531
+ if (adFormat == 1){
532
+ [self fireEvent:@"" event:@"on.appOpenAd.dismissed" withData:nil];
533
+ NSLog(@"Ad did dismiss full screen content App Open Ad.");
534
+ } else if (adFormat == 2){
535
+ [self fireEvent:@"" event:@"on.interstitial.dismissed" withData:nil];
536
+ NSLog(@"Ad did dismiss full screen content interstitial.");
537
+ } else if (adFormat == 3) {
538
+ [self fireEvent:@"" event:@"on.rewarded.dismissed" withData:nil];
539
+ NSLog(@"Ad did dismiss full screen content rewarded.");
540
+ } else if (adFormat == 4) {
541
+ [self fireEvent:@"" event:@"on.rewardedInt.dismissed" withData:nil];
542
+ NSLog(@"Ad did dismiss full screen content interstitial rewarded.");
543
+ }
544
+ }
545
+ #pragma mark Cleanup
546
+ - (void)dealloc {
547
+ self.appOpenAd = nil;
548
+ self.bannerView = nil;
549
+ self.interstitial = nil;
550
+ self.rewardedAd = nil;
551
+ self.rewardedInterstitialAd = nil;
552
+ }
553
+ @end
554
+
@@ -4,8 +4,8 @@ exports.initialize = function (success, error) {
4
4
  exec(success, error, 'emiAdmobPlugin', 'initialize', []);
5
5
  };
6
6
 
7
- exports.loadAppOpenAd = function (arg0, arg1, arg2, success, error) {
8
- exec(success, error, 'emiAdmobPlugin', 'loadAppOpenAd', [arg0, arg1, arg2]);
7
+ exports.loadAppOpenAd = function (arg0, arg1, success, error) {
8
+ exec(success, error, 'emiAdmobPlugin', 'loadAppOpenAd', [arg0, arg1]);
9
9
  };
10
10
 
11
11
  exports.showAppOpenAd = function (success, error) {
@@ -24,24 +24,28 @@ exports.removeBannerAd = function (arg0, success, error) {
24
24
  exec(success, error, 'emiAdmobPlugin', 'removeBannerAd', [arg0]);
25
25
  };
26
26
 
27
- exports.loadInterstitialAd = function (arg0, arg1, arg2, success, error) {
28
- exec(success, error, 'emiAdmobPlugin', 'loadInterstitialAd', [arg0, arg1, arg2]);
27
+ exports.hideBannerAd = function (success, error) {
28
+ exec(success, error, 'emiAdmobPlugin', 'hideBannerAd', []);
29
+ };
30
+
31
+ exports.loadInterstitialAd = function (arg0, arg1, success, error) {
32
+ exec(success, error, 'emiAdmobPlugin', 'loadInterstitialAd', [arg0, arg1]);
29
33
  };
30
34
 
31
35
  exports.showInterstitialAd = function (success, error) {
32
36
  exec(success, error, 'emiAdmobPlugin', 'showInterstitialAd', []);
33
37
  };
34
38
 
35
- exports.loadRewardedAd = function (arg0, arg1, arg2, success, error) {
36
- exec(success, error, 'emiAdmobPlugin', 'loadRewardedAd', [arg0, arg1, arg2]);
39
+ exports.loadRewardedAd = function (arg0, arg1, success, error) {
40
+ exec(success, error, 'emiAdmobPlugin', 'loadRewardedAd', [arg0, arg1]);
37
41
  };
38
42
 
39
43
  exports.showRewardedAd = function (success, error) {
40
44
  exec(success, error, 'emiAdmobPlugin', 'showRewardedAd', []);
41
45
  };
42
46
 
43
- exports.loadRewardedInterstitialAd = function (arg0, arg1, arg2, success, error) {
44
- exec(success, error, 'emiAdmobPlugin', 'loadRewardedInterstitialAd', [arg0, arg1, arg2]);
47
+ exports.loadRewardedInterstitialAd = function (arg0, arg1, success, error) {
48
+ exec(success, error, 'emiAdmobPlugin', 'loadRewardedInterstitialAd', [arg0, arg1]);
45
49
  };
46
50
 
47
51
  exports.showRewardedInterstitialAd = function (success, error) {
@@ -60,6 +64,6 @@ exports.targeting = function (arg0, arg1, arg2, success, error) {
60
64
  exec(success, error, 'emiAdmobPlugin', 'targeting', [arg0, arg1, arg2]);
61
65
  };
62
66
 
63
- exports.globalSettings = function (arg0, arg1, arg2, success, error) {
64
- exec(success, error, 'emiAdmobPlugin', 'globalSettings', [arg0, arg1, arg2]);
67
+ exports.globalSettings = function (arg0, arg1, arg2, arg3, arg4, arg5, success, error) {
68
+ exec(success, error, 'emiAdmobPlugin', 'globalSettings', [arg0, arg1, arg2, arg3, arg4, arg5]);
65
69
  };