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