emi-indo-cordova-plugin-admob 1.4.1 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,3 @@
1
-
2
1
  #import "emiAdmobPlugin.h"
3
2
  #import <Cordova/CDVPlugin.h>
4
3
  #import <UserMessagingPlatform/UserMessagingPlatform.h>
@@ -11,191 +10,157 @@
11
10
  @synthesize interstitial;
12
11
  @synthesize rewardedInterstitialAd;
13
12
  @synthesize rewardedAd;
13
+ @synthesize command;
14
+ @synthesize responseInfo;
14
15
  @synthesize isPrivacyOptionsRequired;
15
16
  int idfaStatus = 0;
16
17
  int fromStatus = 0;
17
18
  int adFormat = 0;
18
19
  int adWidth = 320;
20
+ BOOL auto_Show = NO;
21
+ NSString *Npa = @"1";
22
+ NSString *Position = @"bottom";
23
+ BOOL EnableCollapsible = NO;
24
+ BOOL ResponseInfo = NO;
25
+ int isAdSkip = 0;
19
26
  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];
27
+ BOOL UnderAgeOfConsent = NO;- (void)initialize:(CDVInvokedUrlCommand*)command { GADMobileAds *ads = [GADMobileAds sharedInstance];
183
28
  [ads startWithCompletionHandler:^(GADInitializationStatus *status) {
184
29
  // Optional: Log each adapter's initialization latency.
185
30
  NSDictionary *adapterStatuses = [status adapterStatusesByClassName];
186
31
  for (NSString *adapter in adapterStatuses) {
187
32
  GADAdapterStatus *adapterStatus = adapterStatuses[adapter];
188
33
  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
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
195
160
  {
196
- if ([size isEqualToString:@"Anchored_adaptive"]) {
161
+ if ([size isEqualToString:@"ANCHORED"]) {
197
162
  return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(adWidth);
198
- } else if ([size isEqualToString:@"Inline_adaptive"]) {
163
+ } else if ([size isEqualToString:@"IN_LINE"]) {
199
164
  return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(adWidth);
200
165
  } else if ([size isEqualToString:@"BANNER"]) {
201
166
  return GADAdSizeBanner;
@@ -208,340 +173,345 @@ BOOL isIAB = NO;
208
173
  } else {
209
174
  return GADAdSizeBanner;
210
175
  }
211
- }
212
- - (void)loadBannerAdIOS:(CDVInvokedUrlCommand*)command {
176
+ }- (void)loadBannerAd:(CDVInvokedUrlCommand*)command {
213
177
  if(self.bannerView) {
214
178
  NSLog(@"Admob banner has been initing");
215
179
  return;
216
180
  }
217
181
  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];
182
+ NSString *callbackId = command.callbackId; adFormat = 3; if (adFormat == 3) { UIView *parentView = [self.webView superview]; NSString* adUnitId = [command.arguments objectAtIndex:0];
183
+ // NSNumber* x = [command.arguments objectAtIndex:1];
184
+ // NSNumber* y = [command.arguments objectAtIndex:2];
185
+ NSString* position = [command.arguments objectAtIndex:1];
186
+ NSString* size = [command.arguments objectAtIndex:2]; NSString* collapsible = [command.arguments objectAtIndex:3];
187
+ NSNumber* adaptive_Width = [command.arguments objectAtIndex:4];
188
+ BOOL autoShow = [[command argumentAtIndex:5] boolValue];
189
+ auto_Show = autoShow;
190
+ int intValue = [adaptive_Width intValue];
191
+ adWidth = intValue;
192
+ Position = position;
193
+ // float posX = [x floatValue];
194
+ // float posY = [y floatValue];
195
+ GADAdSize sizes = [self __AdSizeFromString:size]; // CGPoint origin = CGPointMake(posX,posY);
196
+ self.bannerView = [[GADBannerView alloc]
197
+ initWithAdSize:sizes]; GADRequest *request = [GADRequest request];
198
+ GADExtras *extras = [[GADExtras alloc] init];
199
+ if (EnableCollapsible){
200
+ extras.additionalParameters = @{@"collapsible" : collapsible};
201
+ }
202
+ extras.additionalParameters = @{@"npa": Npa};
203
+ [request registerAdNetworkExtras:extras];
204
+ self.bannerView.adUnitID = adUnitId;
205
+ self.bannerView.rootViewController = self.viewController;
206
+ self.bannerView.delegate = self;
207
+ [self.bannerView loadRequest:request];
208
+ self.bannerView.hidden = YES;
209
+ [parentView addSubview:self.bannerView];
210
+ [parentView bringSubviewToFront:self.bannerView]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
249
211
  } else {
250
212
  NSLog(@"Admob Option invalid for banner");
251
213
  pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
252
214
  }
253
215
  [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
254
- }
255
- - (void)showBannerAd:(CDVInvokedUrlCommand*)command {
216
+ }- (void)showBannerAd:(CDVInvokedUrlCommand*)command {
256
217
  CDVPluginResult *pluginResult;
257
218
  NSString *callbackId = command.callbackId;
258
219
  if(self.bannerView) {
259
- self.bannerView.hidden = NO;
260
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
220
+ self.bannerView.hidden = NO; [self addBannerViewToView:command]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
261
221
  } else {
222
+ [self fireEvent:@"" event:@"on.banner.failed.show" withData:nil];
262
223
  pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
263
224
  }
264
225
  [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];
226
+ }- (void)addBannerViewToView:(CDVInvokedUrlCommand*)command{ bannerView.translatesAutoresizingMaskIntoConstraints = NO;
227
+ [self.viewController.view addSubview:bannerView];
228
+ if ([Position isEqualToString:@"bottom-center"]){
229
+ [self.viewController.view addConstraints:@[
230
+ [NSLayoutConstraint constraintWithItem:bannerView
231
+ attribute:NSLayoutAttributeBottom
232
+ relatedBy:NSLayoutRelationEqual
233
+ toItem:self.viewController.view.safeAreaLayoutGuide
234
+ attribute:NSLayoutAttributeBottom
235
+ multiplier:1
236
+ constant:0 ],
237
+ [NSLayoutConstraint constraintWithItem:bannerView
238
+ attribute:NSLayoutAttributeCenterX
239
+ relatedBy:NSLayoutRelationEqual
240
+ toItem:self.viewController.view
241
+ attribute:NSLayoutAttributeCenterX
242
+ multiplier:1
243
+ constant:0]
244
+ ]];
286
245
  } 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 {
246
+ [self.viewController.view addConstraints:@[
247
+ [NSLayoutConstraint constraintWithItem:bannerView
248
+ attribute:NSLayoutAttributeTop
249
+ relatedBy:NSLayoutRelationEqual
250
+ toItem:self.viewController.view.safeAreaLayoutGuide
251
+ attribute:NSLayoutAttributeTop
252
+ multiplier:1
253
+ constant:0],
254
+ [NSLayoutConstraint constraintWithItem:bannerView
255
+ attribute:NSLayoutAttributeCenterX
256
+ relatedBy:NSLayoutRelationEqual
257
+ toItem:self.viewController.view
258
+ attribute:NSLayoutAttributeCenterX
259
+ multiplier:1
260
+ constant:0]
261
+ ]];
262
+ }}- (void)hideBannerAd:(CDVInvokedUrlCommand*)command {
263
+ CDVPluginResult *pluginResult;
264
+ NSString *callbackId = command.callbackId;
265
+ if(self.bannerView) {
266
+ self.bannerView.hidden = YES;
267
+ [self fireEvent:@"" event:@"on.banner.hide" withData:nil];
268
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
269
+ } else {
323
270
  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;
271
+ }
272
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
273
+ }- (void)removeBannerAd:(CDVInvokedUrlCommand*)command {
274
+ CDVPluginResult *pluginResult;
275
+ NSString *callbackId = command.callbackId;
276
+ if(self.bannerView) {
277
+ self.bannerView.hidden = YES;
278
+ [self.bannerView removeFromSuperview];
279
+ self.bannerView = nil;
280
+ [self fireEvent:@"" event:@"on.banner.remove" withData:nil];
281
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
282
+ } else {
283
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
284
+ }
285
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];}- (void)loadAppOpenAd:(CDVInvokedUrlCommand *)command {
286
+ CDVPluginResult *pluginResult;
287
+ NSString *callbackId = command.callbackId;
288
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
289
+ BOOL autoShow = [[command argumentAtIndex:1] boolValue];
290
+ auto_Show = autoShow;
291
+ adFormat = 1;
292
+ self.appOpenAd = nil;
293
+ if (adFormat == 1){
294
+ GADRequest *request = [GADRequest request];
295
+ GADExtras *extras = [[GADExtras alloc] init];
296
+ extras.additionalParameters = @{@"npa": Npa};
297
+ [request registerAdNetworkExtras:extras];
298
+ [GADAppOpenAd loadWithAdUnitID:adUnitId
299
+ request:request
300
+ orientation:UIInterfaceOrientationPortrait
301
+ completionHandler:^(GADAppOpenAd *ad, NSError *error) {
302
+ if (error) {
303
+ [self fireEvent:@"" event:@"on.appOpenAd.failed.loaded" withData:nil];
304
+ NSLog(@"Failed to load App Open Ad ad with error: %@", [error localizedDescription]); return;
305
+ }
306
+ self.appOpenAd = ad;
307
+ self.appOpenAd.fullScreenContentDelegate = self;
308
+ [self fireEvent:@"" event:@"on.appOpenAd.loaded" withData:nil];
309
+ if (auto_Show){ if (self.appOpenAd && [self.appOpenAd
310
+ canPresentFromRootViewController:self.viewController
311
+ error:nil]) { [self.appOpenAd presentFromRootViewController:self.viewController]; } else {
312
+ [self fireEvent:@"" event:@"on.appOpenAd.failed.show" withData:nil];
313
+ }}
314
+ }]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
315
+ } [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];}- (void)showAppOpenAd:(CDVInvokedUrlCommand *)command {
316
+ CDVPluginResult *pluginResult;
317
+ NSString *callbackId = command.callbackId;
318
+ if (self.appOpenAd && [self.appOpenAd
319
+ canPresentFromRootViewController:self.viewController
320
+ error:nil]) { [self.appOpenAd presentFromRootViewController:self.viewController]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; } else { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
321
+ [self fireEvent:@"" event:@"on.appOpenAd.failed.show" withData:nil];
380
322
  }
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;
323
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
324
+ }- (void)loadInterstitialAd:(CDVInvokedUrlCommand *)command {
325
+ CDVPluginResult *pluginResult;
326
+ NSString *callbackId = command.callbackId;
327
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
328
+ BOOL autoShow = [[command argumentAtIndex:1] boolValue];
329
+ auto_Show = autoShow;
330
+ adFormat = 2;
331
+ if (adFormat == 2){
332
+ GADRequest *request = [GADRequest request];
333
+ [GADInterstitialAd
334
+ loadWithAdUnitID:adUnitId
335
+ request:request
336
+ completionHandler:^(GADInterstitialAd *ad, NSError *error) {
337
+ if (error) { NSLog(@"Failed to load interstitial ad with error: %@", [error localizedDescription]);
338
+ // [self fireEvent:@"" event:@"on.interstitial.failed.load" withData:nil]; return;
339
+ } self.interstitial = ad;
340
+ self.interstitial.fullScreenContentDelegate = self;
341
+ [self fireEvent:@"" event:@"on.interstitial.loaded" withData:nil]; if (auto_Show){ if (self.interstitial && [self.interstitial
342
+ canPresentFromRootViewController:self.viewController error:nil]) { [self.interstitial presentFromRootViewController:self.viewController]; } else { [self fireEvent:@"" event:@"on.interstitial.failed.show" withData:nil];
343
+ } } }];
344
+ } pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
345
+ }- (void)showInterstitialAd:(CDVInvokedUrlCommand *)command {
346
+ CDVPluginResult *pluginResult;
347
+ NSString *callbackId = command.callbackId;
348
+ if (self.interstitial && [self.interstitial
349
+ canPresentFromRootViewController:self.viewController error:nil]) { [self.interstitial presentFromRootViewController:self.viewController];
350
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
351
+ } else {
352
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
353
+ [self fireEvent:@"" event:@"on.interstitial.failed.show" withData:nil];
354
+ } [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
355
+ }- (void)loadRewardedInterstitialAd:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult;
356
+ NSString *callbackId = command.callbackId;
357
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
358
+ BOOL autoShow = [[command argumentAtIndex:1] boolValue];
359
+ auto_Show = autoShow;
360
+ adFormat = 4;
361
+ if (adFormat == 4){ GADRequest *request = [GADRequest request];
362
+ [GADRewardedInterstitialAd
363
+ loadWithAdUnitID:adUnitId
364
+ request:request
365
+ completionHandler:^(GADRewardedInterstitialAd *ad, NSError *error) {
366
+ if (error) {
367
+ NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
368
+ return;
369
+ }
370
+ self.rewardedInterstitialAd = ad; isAdSkip = 1;
371
+ NSLog(@"Rewarded ad loaded.");
372
+ self.rewardedInterstitialAd.fullScreenContentDelegate = self;
373
+ [self fireEvent:@"" event:@"on.rewardedInt.loaded" withData:nil]; if (auto_Show){ if (self.rewardedInterstitialAd && [self.rewardedInterstitialAd canPresentFromRootViewController:self.viewController error:nil]) { [self.rewardedInterstitialAd presentFromRootViewController:self.viewController
374
+ userDidEarnRewardHandler:^{
375
+ GADAdReward *reward =
376
+ self.rewardedInterstitialAd.adReward;
377
+ [self fireEvent:@"" event:@"on.rewardedInt.userEarnedReward" withData:nil];
378
+ isAdSkip = 2;
379
+ NSString *rewardMessage = [NSString stringWithFormat:@"Reward received with "
380
+ @"currency %@ , amount %ld",
381
+ reward.type, [reward.amount longValue]];
382
+ NSLog(@"%@", rewardMessage); }]; } else { [self fireEvent:@"" event:@"on.rewardedInt.failed.show" withData:nil];
383
+ } } }];
429
384
  }
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
- }
385
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
386
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
387
+ }-(void)showRewardedInterstitialAd:(CDVInvokedUrlCommand *)command {
388
+ CDVPluginResult *pluginResult;
389
+ NSString *callbackId = command.callbackId;
390
+ if (self.rewardedInterstitialAd && [self.rewardedInterstitialAd canPresentFromRootViewController:self.viewController error:nil]) { [self.rewardedInterstitialAd presentFromRootViewController:self.viewController
391
+ userDidEarnRewardHandler:^{
392
+ GADAdReward *reward =
393
+ self.rewardedInterstitialAd.adReward;
394
+ [self fireEvent:@"" event:@"on.rewardedInt.userEarnedReward" withData:nil];
395
+ isAdSkip = 2;
396
+ NSString *rewardMessage = [NSString stringWithFormat:@"Reward received with "
397
+ @"currency %@ , amount %ld",
398
+ reward.type, [reward.amount longValue]];
399
+ NSLog(@"%@", rewardMessage); }]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; } else {
400
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
401
+ [self fireEvent:@"" event:@"on.rewardedInt.failed.show" withData:nil];
402
+ } [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
403
+ }- (void)loadRewardedAd:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult;
404
+ NSString *callbackId = command.callbackId;
405
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
406
+ BOOL autoShow = [[command argumentAtIndex:1] boolValue];
407
+ auto_Show = autoShow;
408
+ adFormat = 3;
409
+ if (adFormat == 3){
410
+ GADRequest *request = [GADRequest request];
411
+ [GADRewardedAd
412
+ loadWithAdUnitID:adUnitId
413
+ request:request
414
+ completionHandler:^(GADRewardedAd *ad, NSError *error) {
415
+ if (error) {
416
+ NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
417
+ return;
418
+ }
419
+ self.rewardedAd = ad;
420
+ NSLog(@"Rewarded ad loaded.");
421
+ isAdSkip = 0;
422
+ self.rewardedAd.fullScreenContentDelegate = self;
423
+ [self fireEvent:@"" event:@"on.rewarded.loaded" withData:nil]; if (auto_Show){ if (self.rewardedAd && [self.rewardedAd canPresentFromRootViewController:self.viewController error:nil]) { [self.rewardedAd presentFromRootViewController:self.viewController
424
+ userDidEarnRewardHandler:^{
425
+ GADAdReward *reward =
426
+ self.rewardedAd.adReward;
427
+ [self fireEvent:@"" event:@"on.reward.userEarnedReward" withData:nil];
428
+ isAdSkip = 2;
429
+ NSString *rewardMessage = [NSString stringWithFormat:@"Reward received with currency %@ , amount %lf", reward.type, [reward.amount doubleValue]];
430
+ NSLog(@"%@", rewardMessage); }]; } else { [self fireEvent:@"" event:@"on.rewarded.failed.show" withData:nil];
431
+ } } }];
432
+ }
433
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
434
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
435
+ }-(void)showRewardedAd:(CDVInvokedUrlCommand *)command {
436
+ CDVPluginResult *pluginResult;
437
+ NSString *callbackId = command.callbackId;
438
+ if (self.rewardedAd && [self.rewardedAd canPresentFromRootViewController:self.viewController error:nil]) { [self.rewardedAd presentFromRootViewController:self.viewController
439
+ userDidEarnRewardHandler:^{
440
+ GADAdReward *reward =
441
+ self.rewardedAd.adReward;
442
+ [self fireEvent:@"" event:@"on.reward.userEarnedReward" withData:nil];
443
+ isAdSkip = 2;
444
+ NSString *rewardMessage = [NSString stringWithFormat:@"Reward received with currency %@ , amount %lf", reward.type, [reward.amount doubleValue]];
445
+ NSLog(@"%@", rewardMessage); }]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; } else {
446
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
447
+ [self fireEvent:@"" event:@"on.rewarded.failed.show" withData:nil];
448
+ } [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
449
+ }- (void) fireEvent:(NSString *)obj event:(NSString *)eventName withData:(NSString *)jsonStr {
450
+ NSString* js;
451
+ if(obj && [obj isEqualToString:@"window"]) {
452
+ js = [NSString stringWithFormat:@"var evt=document.createEvent(\"UIEvents\");evt.initUIEvent(\"%@\",true,false,window,0);window.dispatchEvent(evt);", eventName];
453
+ } else if(jsonStr && [jsonStr length]>0) {
454
+ js = [NSString stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@',%@);", eventName, jsonStr];
455
+ } else {
456
+ js = [NSString stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@');", eventName];
457
+ }
458
+ [self.commandDelegate evalJs:js];
459
+ }
472
460
  #pragma mark GADBannerViewDelegate implementation
473
- - (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
461
+ -(void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
474
462
  [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
- }
463
+ NSLog(@"bannerViewDidReceiveAd");
464
+ if (auto_Show){
465
+ if(self.bannerView) {
466
+ [self addBannerViewToView:command];
467
+ self.bannerView.hidden = NO;
468
+ }
469
+ } else { [self fireEvent:@"" event:@"on.banner.failed.show" withData:nil];
470
+ }}- (void)bannerView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error {
471
+ [self fireEvent:@"" event:@"on.banner.failed.load" withData:nil];
472
+ NSLog(@"bannerView:didFailToReceiveAdWithError: %@", [error localizedDescription]);
473
+ }- (void)bannerViewDidRecordImpression:(GADBannerView *)bannerView {
474
+ [self fireEvent:@"" event:@"on.banner.impression" withData:nil];
475
+ NSLog(@"bannerViewDidRecordImpression");
476
+ }- (void)bannerViewWillPresentScreen:(GADBannerView *)bannerView {
477
+ [self fireEvent:@"" event:@"on.banner.open" withData:nil];
478
+ NSLog(@"bannerViewWillPresentScreen");
479
+ }- (void)bannerViewWillDismissScreen:(GADBannerView *)bannerView {
480
+ [self fireEvent:@"" event:@"on.banner.close" withData:nil];
481
+ NSLog(@"bannerViewWillDismissScreen");
482
+ }- (void)bannerViewDidDismissScreen:(GADBannerView *)bannerView {
483
+ [self fireEvent:@"" event:@"on.banner.did.dismiss" withData:nil];
484
+ NSLog(@"bannerViewDidDismissScreen");
485
+ }
497
486
  #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];
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];
505
489
  [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
- }
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."); }}
545
515
  #pragma mark Cleanup
546
516
  - (void)dealloc {
547
517
  self.appOpenAd = nil;
@@ -551,4 +521,3 @@ if (adFormat == 3){
551
521
  self.rewardedInterstitialAd = nil;
552
522
  }
553
523
  @end
554
-