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

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