emi-indo-cordova-plugin-admob 1.4.2 → 1.4.4

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