emi-indo-cordova-plugin-admob 2.0.5 → 2.0.7
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/README.md +199 -53
- package/example/capacitor.config.json +1 -1
- package/example/config.xml +7 -0
- package/example/package.json +1 -1
- package/example/www/css/index.css +59 -109
- package/example/www/index.html +38 -39
- package/example/www/js/bannerAd.js +7 -62
- package/example/www/js/deviceready.js +6 -6
- package/example/www/js/interstitialAd.js +0 -2
- package/example/www/js/optionalFirebaseAnalytics.js +0 -2
- package/example/www/js/rewardedAd.js +0 -2
- package/package.json +1 -1
- package/plugin.xml +7 -9
- package/src/android/emiAdmobPlugin.kt +438 -256
- package/src/ios/emiAdmobPlugin.m +280 -184
- package/www/emiAdmobPlugin.js +3 -0
package/src/ios/emiAdmobPlugin.m
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
#import <Foundation/Foundation.h>
|
6
6
|
#import <UserMessagingPlatform/UserMessagingPlatform.h>
|
7
7
|
#import <Cordova/CDVViewController.h>
|
8
|
+
|
8
9
|
@implementation emiAdmobPlugin
|
9
10
|
@synthesize appOpenAd;
|
10
11
|
@synthesize bannerView;
|
@@ -81,6 +82,10 @@ NSString *setKeyword = @"";
|
|
81
82
|
|
82
83
|
|
83
84
|
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
84
89
|
- (void)isResponseInfo:(BOOL)value {
|
85
90
|
isResponseInfo = value;
|
86
91
|
}
|
@@ -173,35 +178,41 @@ NSString *setKeyword = @"";
|
|
173
178
|
|
174
179
|
|
175
180
|
- (void)requestIDFA:(CDVInvokedUrlCommand *)command {
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
181
|
+
__block CDVPluginResult *pluginResult;
|
182
|
+
NSString *callbackId = command.callbackId;
|
183
|
+
|
184
|
+
if (@available(iOS 14, *)) {
|
185
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
186
|
+
// Added a 1-second pause before performing a tracking authorization request
|
187
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
188
|
+
|
189
|
+
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
|
190
|
+
if (status == ATTrackingManagerAuthorizationStatusDenied) {
|
191
|
+
attStatus = ATTrackingManagerAuthorizationStatusDenied;
|
192
|
+
} else if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
|
193
|
+
attStatus = ATTrackingManagerAuthorizationStatusAuthorized;
|
194
|
+
} else if (status == ATTrackingManagerAuthorizationStatusRestricted) {
|
195
|
+
attStatus = ATTrackingManagerAuthorizationStatusRestricted;
|
196
|
+
} else if (status == ATTrackingManagerAuthorizationStatusNotDetermined) {
|
197
|
+
attStatus = ATTrackingManagerAuthorizationStatusNotDetermined;
|
198
|
+
}
|
199
|
+
[self fireEvent:@"" event:@"on.getIDFA.status" withData:nil];
|
200
|
+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:attStatus];
|
201
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
|
202
|
+
}];
|
203
|
+
});
|
204
|
+
});
|
205
|
+
} else {
|
206
|
+
[self fireEvent:@"" event:@"on.getIDFA.error" withData:nil];
|
207
|
+
|
208
|
+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"iOS 14+ not found"];
|
209
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
|
210
|
+
}
|
203
211
|
}
|
204
212
|
|
213
|
+
|
214
|
+
|
215
|
+
|
205
216
|
- (void)startGoogleMobileAdsSDK {
|
206
217
|
static dispatch_once_t onceToken;
|
207
218
|
dispatch_once(&onceToken, ^{
|
@@ -559,7 +570,7 @@ NSString *setKeyword = @"";
|
|
559
570
|
[self.bannerViewLayout.trailingAnchor
|
560
571
|
constraintEqualToAnchor:rootView.trailingAnchor]
|
561
572
|
.active = YES;
|
562
|
-
|
573
|
+
[self.bannerViewLayout.heightAnchor constraintEqualToConstant:bannerHeightFinal]
|
563
574
|
.active = YES;
|
564
575
|
}
|
565
576
|
|
@@ -573,9 +584,21 @@ NSString *setKeyword = @"";
|
|
573
584
|
|
574
585
|
[self.bannerViewLayout addSubview:self.bannerView];
|
575
586
|
[self.bannerViewLayout bringSubviewToFront:self.bannerView];
|
587
|
+
|
588
|
+
if (isSetOverlapping) {
|
589
|
+
|
590
|
+
if (auto_Show && self.bannerView) {
|
591
|
+
if (isSetOverlapping){
|
592
|
+
self.bannerView.hidden = NO;
|
593
|
+
[self setBodyHeight:self.command];
|
594
|
+
}
|
595
|
+
}
|
596
|
+
|
597
|
+
|
598
|
+
}
|
576
599
|
|
577
600
|
} @catch (NSException *exception) {
|
578
|
-
|
601
|
+
NSLog(@"Exception: %@", exception.reason);
|
579
602
|
}
|
580
603
|
});
|
581
604
|
}
|
@@ -621,7 +644,7 @@ NSString *setKeyword = @"";
|
|
621
644
|
|
622
645
|
if (adFormat == 5) {
|
623
646
|
dispatch_async(dispatch_get_main_queue(), ^{
|
624
|
-
UIView *parentView =
|
647
|
+
UIView *parentView = self.viewController.view;
|
625
648
|
CGRect frame = self.bannerView.frame;
|
626
649
|
|
627
650
|
if (@available(iOS 11.0, *)) {
|
@@ -636,7 +659,25 @@ NSString *setKeyword = @"";
|
|
636
659
|
|
637
660
|
GADAdSize siz = [self __AdSizeFromString:size];
|
638
661
|
self.bannerView = [[GADBannerView alloc] initWithAdSize:siz];
|
639
|
-
|
662
|
+
|
663
|
+
|
664
|
+
CGSize bannerSize = self.bannerView.bounds.size;
|
665
|
+
CGFloat screenWidth = parentView.bounds.size.width;
|
666
|
+
CGFloat screenHeight = parentView.bounds.size.height;
|
667
|
+
|
668
|
+
// Default to top-center
|
669
|
+
CGFloat originX = (screenWidth - bannerSize.width) / 2;
|
670
|
+
CGFloat originY = 0;
|
671
|
+
|
672
|
+
if ([setPosition isEqualToString:@"bottom-center"]) {
|
673
|
+
originY = screenHeight - bannerSize.height;
|
674
|
+
} else if ([setPosition isEqualToString:@"top-center"]) {
|
675
|
+
originY = 0;
|
676
|
+
}
|
677
|
+
|
678
|
+
self.bannerView.frame = CGRectMake(originX, originY, bannerSize.width, bannerSize.height);
|
679
|
+
|
680
|
+
|
640
681
|
GADExtras *extras = [[GADExtras alloc] init];
|
641
682
|
|
642
683
|
if (isCollapsible) {
|
@@ -651,8 +692,10 @@ NSString *setKeyword = @"";
|
|
651
692
|
self.bannerView.delegate = self;
|
652
693
|
[self.bannerView loadRequest:self.globalRequest];
|
653
694
|
self.bannerView.hidden = YES;
|
654
|
-
[parentView
|
655
|
-
|
695
|
+
if (![parentView.subviews containsObject:self.bannerView]) {
|
696
|
+
[parentView addSubview:self.bannerView];
|
697
|
+
[parentView bringSubviewToFront:self.bannerView];
|
698
|
+
}
|
656
699
|
});
|
657
700
|
|
658
701
|
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
@@ -669,7 +712,10 @@ NSString *setKeyword = @"";
|
|
669
712
|
@try {
|
670
713
|
if (self.bannerView) {
|
671
714
|
self.bannerView.hidden = NO;
|
672
|
-
|
715
|
+
if (isSetOverlapping){
|
716
|
+
[self setBodyHeight:command];
|
717
|
+
}
|
718
|
+
|
673
719
|
} else {
|
674
720
|
[self fireEvent:@"" event:@"on.banner.failed.show" withData:nil];
|
675
721
|
}
|
@@ -679,147 +725,126 @@ NSString *setKeyword = @"";
|
|
679
725
|
}
|
680
726
|
}
|
681
727
|
|
728
|
+
- (UIView*)findWebViewInView:(UIView*)view {
|
729
|
+
if ([view isKindOfClass:NSClassFromString(@"WKWebView")] || [view isKindOfClass:NSClassFromString(@"UIWebView")]) {
|
730
|
+
return view;
|
731
|
+
}
|
682
732
|
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
[NSLayoutConstraint
|
689
|
-
constraintWithItem:bannerView
|
690
|
-
attribute:NSLayoutAttributeBottom
|
691
|
-
relatedBy:NSLayoutRelationEqual
|
692
|
-
toItem:self.viewController.view.safeAreaLayoutGuide
|
693
|
-
attribute:NSLayoutAttributeBottom
|
694
|
-
multiplier:1
|
695
|
-
constant:0],
|
696
|
-
[NSLayoutConstraint constraintWithItem:bannerView
|
697
|
-
attribute:NSLayoutAttributeCenterX
|
698
|
-
relatedBy:NSLayoutRelationEqual
|
699
|
-
toItem:self.viewController.view
|
700
|
-
attribute:NSLayoutAttributeCenterX
|
701
|
-
multiplier:1
|
702
|
-
constant:0]
|
703
|
-
]];
|
704
|
-
} else if ([setPosition isEqualToString:@"top-center"]) {
|
705
|
-
|
706
|
-
[self.viewController.view addConstraints:@[
|
707
|
-
[NSLayoutConstraint
|
708
|
-
constraintWithItem:bannerView
|
709
|
-
attribute:NSLayoutAttributeTop
|
710
|
-
relatedBy:NSLayoutRelationEqual
|
711
|
-
toItem:self.viewController.view.safeAreaLayoutGuide
|
712
|
-
attribute:NSLayoutAttributeTop
|
713
|
-
multiplier:1
|
714
|
-
constant:0],
|
715
|
-
[NSLayoutConstraint constraintWithItem:bannerView
|
716
|
-
attribute:NSLayoutAttributeCenterX
|
717
|
-
relatedBy:NSLayoutRelationEqual
|
718
|
-
toItem:self.viewController.view
|
719
|
-
attribute:NSLayoutAttributeCenterX
|
720
|
-
multiplier:1
|
721
|
-
constant:0]
|
722
|
-
]];
|
723
|
-
|
724
|
-
} else {
|
725
|
-
[self.viewController.view addConstraints:@[
|
726
|
-
[NSLayoutConstraint
|
727
|
-
constraintWithItem:bannerView
|
728
|
-
attribute:NSLayoutAttributeBottom
|
729
|
-
relatedBy:NSLayoutRelationEqual
|
730
|
-
toItem:self.viewController.view.safeAreaLayoutGuide
|
731
|
-
attribute:NSLayoutAttributeTop
|
732
|
-
multiplier:1
|
733
|
-
constant:0],
|
734
|
-
[NSLayoutConstraint constraintWithItem:bannerView
|
735
|
-
attribute:NSLayoutAttributeCenterX
|
736
|
-
relatedBy:NSLayoutRelationEqual
|
737
|
-
toItem:self.viewController.view
|
738
|
-
attribute:NSLayoutAttributeCenterX
|
739
|
-
multiplier:1
|
740
|
-
constant:0]
|
741
|
-
]];
|
742
|
-
}
|
743
|
-
if (isSetOverlapping){
|
744
|
-
[self bannerOverlapping];
|
733
|
+
for (UIView* subview in view.subviews) {
|
734
|
+
UIView* found = [self findWebViewInView:subview];
|
735
|
+
if (found) {
|
736
|
+
return found;
|
737
|
+
}
|
745
738
|
}
|
739
|
+
|
740
|
+
return nil;
|
746
741
|
}
|
747
742
|
|
748
743
|
|
744
|
+
- (void)setBodyHeight:(CDVInvokedUrlCommand*)command {
|
745
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
746
|
+
@try {
|
749
747
|
|
748
|
+
UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
|
749
|
+
UIViewController* rootViewController = keyWindow.rootViewController;
|
750
750
|
|
751
|
+
if (!rootViewController) {
|
752
|
+
CDVPluginResult* errorResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Root ViewController not found"];
|
753
|
+
[self.commandDelegate sendPluginResult:errorResult callbackId:command.callbackId];
|
754
|
+
return;
|
755
|
+
}
|
756
|
+
|
757
|
+
|
758
|
+
[rootViewController.view setNeedsLayout];
|
759
|
+
[rootViewController.view layoutIfNeeded];
|
751
760
|
|
752
|
-
|
753
|
-
if (!self.bannerView || !self.webView) {
|
754
|
-
NSLog(@"[AdPlugin] Error: Missing bannerView or webView. Adjustment skipped.");
|
755
|
-
return;
|
756
|
-
}
|
757
|
-
|
758
|
-
if (isSetOverlapping){
|
759
|
-
|
760
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
761
|
-
@try {
|
761
|
+
UIEdgeInsets safeAreaInsets = rootViewController.view.safeAreaInsets;
|
762
762
|
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
CGFloat navigationBarHeight = 0.0;
|
767
|
-
if (@available(iOS 11.0, *)) {
|
768
|
-
navigationBarHeight = self.viewController.view.safeAreaInsets.bottom;
|
769
|
-
}
|
770
|
-
|
771
|
-
if (!self.bannerContainer) {
|
772
|
-
self.bannerContainer = [[UIView alloc] initWithFrame:CGRectZero];
|
773
|
-
// self.bannerContainer.backgroundColor = [UIColor redColor]; // Debug
|
774
|
-
[self.viewController.view addSubview:self.bannerContainer];
|
775
|
-
}
|
776
|
-
|
777
|
-
if (!self.webViewContainer) {
|
778
|
-
self.webViewContainer = [[UIView alloc] initWithFrame:CGRectZero];
|
779
|
-
// self.webViewContainer.backgroundColor = [UIColor blueColor]; // Debug
|
780
|
-
[self.viewController.view addSubview:self.webViewContainer];
|
781
|
-
}
|
782
|
-
|
783
|
-
CGRect bannerContainerFrame = CGRectZero;
|
784
|
-
if ([setPosition isEqualToString:@"top-center"]) {
|
785
|
-
bannerContainerFrame = CGRectMake(0, 0, screenWidth, bannerHeightFinal);
|
786
|
-
} else if ([setPosition isEqualToString:@"bottom-center"]) {
|
787
|
-
bannerContainerFrame = CGRectMake(0, screenHeight - paddingWebView - bannerHeightFinal - navigationBarHeight, screenWidth, bannerHeightFinal);
|
788
|
-
}
|
789
|
-
self.bannerContainer.frame = bannerContainerFrame;
|
790
|
-
|
791
|
-
self.bannerView.frame = self.bannerContainer.bounds;
|
792
|
-
[self.bannerContainer addSubview:self.bannerView];
|
793
|
-
|
794
|
-
CGRect webViewContainerFrame = CGRectZero;
|
795
|
-
if ([setPosition isEqualToString:@"top-center"]) {
|
796
|
-
webViewContainerFrame = CGRectMake(0, bannerHeightFinal, screenWidth, screenHeight - bannerHeightFinal);
|
797
|
-
} else if ([setPosition isEqualToString:@"bottom-center"]) {
|
798
|
-
|
799
|
-
webViewContainerFrame = CGRectMake(0, 0, screenWidth, screenHeight - bannerHeightFinal - paddingWebView - navigationBarHeight);
|
800
|
-
|
801
|
-
}
|
802
|
-
self.webViewContainer.frame = webViewContainerFrame;
|
803
|
-
|
804
|
-
self.webView.frame = self.webViewContainer.bounds;
|
805
|
-
[self.webViewContainer addSubview:self.webView];
|
806
|
-
|
807
|
-
[self.bannerContainer setNeedsLayout];
|
808
|
-
[self.bannerContainer layoutIfNeeded];
|
809
|
-
[self.webViewContainer setNeedsLayout];
|
810
|
-
[self.webViewContainer layoutIfNeeded];
|
811
|
-
|
812
|
-
|
813
|
-
NSLog(@"[AdPlugin] Banner and WebView are now in separate containers with proper sizing.");
|
814
|
-
} @catch (NSException *exception) {
|
815
|
-
NSLog(@"[AdPlugin] Error adjusting layout for banner and WebView: %@", exception.reason);
|
763
|
+
if (safeAreaInsets.bottom == 0) {
|
764
|
+
safeAreaInsets = keyWindow.safeAreaInsets;
|
816
765
|
}
|
817
|
-
|
818
|
-
|
819
|
-
|
766
|
+
|
767
|
+
CGFloat screenHeight = UIScreen.mainScreen.bounds.size.height;
|
768
|
+
CGFloat screenWidth = UIScreen.mainScreen.bounds.size.width;
|
769
|
+
CGFloat bannerHeight = bannerHeightFinal;
|
770
|
+
CGFloat newHeight = screenHeight - bannerHeight;
|
771
|
+
|
772
|
+
|
773
|
+
if (newHeight <= 0) {
|
774
|
+
|
775
|
+
CDVPluginResult* errorResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid new height"];
|
776
|
+
[self.commandDelegate sendPluginResult:errorResult callbackId:command.callbackId];
|
777
|
+
return;
|
778
|
+
}
|
779
|
+
|
780
|
+
UIView *webView = [self findWebViewInView:rootViewController.view];
|
781
|
+
if (webView) {
|
782
|
+
CGRect webViewFrame = webView.frame;
|
783
|
+
webViewFrame.size.height = newHeight;
|
784
|
+
webView.frame = webViewFrame;
|
785
|
+
} else {
|
786
|
+
NSLog(@"[CordovaBodyHeight] WebView not found");
|
787
|
+
}
|
788
|
+
|
789
|
+
if ([setPosition isEqualToString:@"top-center"]) {
|
790
|
+
CGRect currentBannerFrame = self.bannerView.frame;
|
791
|
+
CGFloat expectedYPosition = safeAreaInsets.top;
|
792
|
+
|
793
|
+
if (fabs(currentBannerFrame.origin.y - expectedYPosition) > 0.1) {
|
794
|
+
CGRect bannerFrame = CGRectMake(0, expectedYPosition, screenWidth, bannerHeight);
|
795
|
+
self.bannerView.frame = bannerFrame;
|
796
|
+
CGRect contentFrame = rootViewController.view.frame;
|
797
|
+
contentFrame.origin.y = bannerHeight + safeAreaInsets.top;
|
798
|
+
contentFrame.size.height = screenHeight - (bannerHeight + safeAreaInsets.top);
|
799
|
+
rootViewController.view.frame = contentFrame;
|
800
|
+
}
|
801
|
+
} else if ([setPosition isEqualToString:@"bottom-center"]) {
|
802
|
+
|
803
|
+
CGRect bannerFrame = CGRectMake(
|
804
|
+
0,
|
805
|
+
screenHeight - bannerHeight - safeAreaInsets.bottom + paddingWebView,
|
806
|
+
screenWidth,
|
807
|
+
bannerHeight
|
808
|
+
);
|
809
|
+
self.bannerView.frame = bannerFrame;
|
810
|
+
|
811
|
+
CGRect contentFrame = rootViewController.view.frame;
|
812
|
+
contentFrame.origin.y = 0;
|
813
|
+
contentFrame.size.height = screenHeight - (bannerHeight + safeAreaInsets.bottom);
|
814
|
+
rootViewController.view.frame = contentFrame;
|
815
|
+
|
816
|
+
} else {
|
817
|
+
CGRect bannerFrame = CGRectMake(
|
818
|
+
0,
|
819
|
+
screenHeight - bannerHeight - safeAreaInsets.bottom + paddingWebView,
|
820
|
+
screenWidth,
|
821
|
+
bannerHeight
|
822
|
+
);
|
823
|
+
self.bannerView.frame = bannerFrame;
|
824
|
+
|
825
|
+
CGRect contentFrame = rootViewController.view.frame;
|
826
|
+
contentFrame.origin.y = 0;
|
827
|
+
contentFrame.size.height = screenHeight - (bannerHeight + safeAreaInsets.bottom);
|
828
|
+
rootViewController.view.frame = contentFrame;
|
829
|
+
|
830
|
+
}
|
831
|
+
|
832
|
+
[self.bannerView setNeedsLayout];
|
833
|
+
[self.bannerView layoutIfNeeded];
|
834
|
+
[rootViewController.view setNeedsLayout];
|
835
|
+
[rootViewController.view layoutIfNeeded];
|
836
|
+
|
837
|
+
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:newHeight];
|
838
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
839
|
+
}
|
840
|
+
@catch (NSException* exception) {
|
841
|
+
NSLog(@"[CordovaBodyHeight] Exception: %@", exception.reason);
|
842
|
+
}
|
843
|
+
});
|
820
844
|
}
|
821
845
|
|
822
846
|
|
847
|
+
|
823
848
|
- (void)metaData:(CDVInvokedUrlCommand *)command {
|
824
849
|
NSDictionary *options = [command.arguments objectAtIndex:0];
|
825
850
|
BOOL useCustomConsentManager = [[options valueForKey:@"useCustomConsentManager"] boolValue];
|
@@ -829,11 +854,11 @@ NSString *setKeyword = @"";
|
|
829
854
|
isCustomConsentManager = useCustomConsentManager;
|
830
855
|
isEnabledKeyword = useCustomKeyword;
|
831
856
|
setKeyword = keywordValue;
|
857
|
+
|
832
858
|
}
|
833
859
|
|
834
860
|
|
835
861
|
- (void)styleBannerAd:(CDVInvokedUrlCommand *)command {
|
836
|
-
|
837
862
|
NSDictionary *options = [command.arguments objectAtIndex:0];
|
838
863
|
BOOL isOverlapping = [[options valueForKey:@"isOverlapping"] boolValue];
|
839
864
|
CGFloat paddingContainer = [[options valueForKey:@"paddingWebView"] floatValue];
|
@@ -841,9 +866,57 @@ NSString *setKeyword = @"";
|
|
841
866
|
isSetOverlapping = isOverlapping;
|
842
867
|
paddingWebView = paddingContainer;
|
843
868
|
|
869
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
870
|
+
@try {
|
871
|
+
|
872
|
+
UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
|
873
|
+
UIViewController *rootViewController = keyWindow.rootViewController;
|
874
|
+
|
875
|
+
if (!rootViewController) {
|
876
|
+
CDVPluginResult *errorResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Root ViewController not found"];
|
877
|
+
[self.commandDelegate sendPluginResult:errorResult callbackId:command.callbackId];
|
878
|
+
return;
|
879
|
+
}
|
880
|
+
|
881
|
+
UIEdgeInsets safeAreaInsets = rootViewController.view.safeAreaInsets;
|
882
|
+
|
883
|
+
if (safeAreaInsets.bottom == 0) {
|
884
|
+
safeAreaInsets = keyWindow.safeAreaInsets;
|
885
|
+
}
|
886
|
+
|
887
|
+
CGFloat screenHeight = UIScreen.mainScreen.bounds.size.height;
|
888
|
+
CGFloat screenWidth = UIScreen.mainScreen.bounds.size.width;
|
889
|
+
|
890
|
+
NSDictionary *data = @{
|
891
|
+
@"screenHeight": @(screenHeight),
|
892
|
+
@"screenWidth": @(screenWidth),
|
893
|
+
@"safeAreaTop": @(safeAreaInsets.top),
|
894
|
+
@"safeAreaBottom": @(safeAreaInsets.bottom)
|
895
|
+
};
|
896
|
+
|
897
|
+
NSError *jsonError;
|
898
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:0 error:&jsonError];
|
899
|
+
|
900
|
+
if (jsonError) {
|
901
|
+
CDVPluginResult *errorResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Error converting dictionary to JSON"];
|
902
|
+
[self.commandDelegate sendPluginResult:errorResult callbackId:command.callbackId];
|
903
|
+
return;
|
904
|
+
}
|
905
|
+
|
906
|
+
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
907
|
+
|
908
|
+
[self fireEvent:@"" event:@"on.style.banner.ad" withData:jsonString];
|
909
|
+
|
910
|
+
|
911
|
+
} @catch (NSException *exception) {
|
912
|
+
NSLog(@"[CordovaBodyHeight] Exception: %@", exception.reason);
|
913
|
+
|
914
|
+
}
|
915
|
+
});
|
844
916
|
}
|
845
917
|
|
846
918
|
|
919
|
+
|
847
920
|
- (GADAdSize)__AdSizeFromString:(NSString *)size {
|
848
921
|
|
849
922
|
if (self.viewWidth == 0) {
|
@@ -872,34 +945,48 @@ NSString *setKeyword = @"";
|
|
872
945
|
|
873
946
|
|
874
947
|
|
948
|
+
- (void)resetWebViewHeight {
|
949
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
950
|
+
UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
|
951
|
+
UIViewController *rootViewController = keyWindow.rootViewController;
|
875
952
|
|
953
|
+
if (!rootViewController) {
|
954
|
+
NSLog(@"[CordovaBodyHeight] Root ViewController not found on reset");
|
955
|
+
return;
|
956
|
+
}
|
876
957
|
|
877
|
-
|
878
|
-
if (!self.webView) {
|
879
|
-
NSLog(@"[AdPlugin] Error: WebView is missing. Reset skipped.");
|
880
|
-
return;
|
881
|
-
}
|
958
|
+
UIEdgeInsets safeAreaInsets = rootViewController.view.safeAreaInsets;
|
882
959
|
|
883
|
-
|
884
|
-
|
960
|
+
if (safeAreaInsets.bottom == 0) {
|
961
|
+
safeAreaInsets = keyWindow.safeAreaInsets;
|
962
|
+
}
|
885
963
|
|
886
|
-
|
964
|
+
CGFloat screenHeight = UIScreen.mainScreen.bounds.size.height;
|
887
965
|
|
888
|
-
|
889
|
-
|
890
|
-
|
966
|
+
CGRect contentFrame = rootViewController.view.frame;
|
967
|
+
contentFrame.origin.y = 0;
|
968
|
+
contentFrame.size.height = screenHeight - safeAreaInsets.bottom;
|
969
|
+
rootViewController.view.frame = contentFrame;
|
891
970
|
|
892
|
-
|
893
|
-
|
971
|
+
UIView *webView = [self findWebViewInView:rootViewController.view];
|
972
|
+
if (webView) {
|
973
|
+
CGRect webViewFrame = webView.frame;
|
974
|
+
webViewFrame.origin.y = 0;
|
975
|
+
webViewFrame.size.height = screenHeight - safeAreaInsets.bottom;
|
976
|
+
webView.frame = webViewFrame;
|
894
977
|
|
895
|
-
}
|
896
|
-
NSLog(@"[
|
978
|
+
} else {
|
979
|
+
NSLog(@"[CordovaBodyHeight] WebView not found on reset");
|
897
980
|
}
|
981
|
+
|
982
|
+
[rootViewController.view setNeedsLayout];
|
983
|
+
[rootViewController.view layoutIfNeeded];
|
898
984
|
});
|
899
985
|
}
|
900
986
|
|
901
987
|
|
902
988
|
|
989
|
+
|
903
990
|
- (void)hideBannerAd:(CDVInvokedUrlCommand *)command {
|
904
991
|
CDVPluginResult *pluginResult;
|
905
992
|
NSString *callbackId = command.callbackId;
|
@@ -915,6 +1002,9 @@ NSString *setKeyword = @"";
|
|
915
1002
|
}
|
916
1003
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
|
917
1004
|
}
|
1005
|
+
|
1006
|
+
|
1007
|
+
|
918
1008
|
- (void)removeBannerAd:(CDVInvokedUrlCommand *)command {
|
919
1009
|
CDVPluginResult *pluginResult;
|
920
1010
|
NSString *callbackId = command.callbackId;
|
@@ -923,8 +1013,8 @@ NSString *setKeyword = @"";
|
|
923
1013
|
self.bannerView.hidden = YES;
|
924
1014
|
[self.bannerView removeFromSuperview];
|
925
1015
|
self.bannerView = nil;
|
926
|
-
|
927
|
-
|
1016
|
+
[self resetWebViewHeight];
|
1017
|
+
[self fireEvent:@"" event:@"on.banner.remove" withData:nil];
|
928
1018
|
});
|
929
1019
|
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
930
1020
|
} else {
|
@@ -1372,7 +1462,10 @@ NSString *setKeyword = @"";
|
|
1372
1462
|
NSDictionary *options = [command.arguments objectAtIndex:0];
|
1373
1463
|
NSString *adUnitId = [options valueForKey:@"adUnitId"];
|
1374
1464
|
BOOL autoShow = [[options valueForKey:@"autoShow"] boolValue];
|
1375
|
-
auto_Show = autoShow;
|
1465
|
+
//auto_Show = autoShow;
|
1466
|
+
|
1467
|
+
__block BOOL shouldAutoShow = autoShow;
|
1468
|
+
|
1376
1469
|
adFormat = 3;
|
1377
1470
|
[self setAdRequest];
|
1378
1471
|
if (adFormat == 3) {
|
@@ -1416,7 +1509,7 @@ NSString *setKeyword = @"";
|
|
1416
1509
|
|
1417
1510
|
|
1418
1511
|
|
1419
|
-
if (
|
1512
|
+
if (shouldAutoShow) {
|
1420
1513
|
NSError *presentError = nil;
|
1421
1514
|
if ([self.rewardedAd canPresentFromRootViewController:self.viewController error:&presentError]) {
|
1422
1515
|
[self.rewardedAd presentFromRootViewController:self.viewController userDidEarnRewardHandler:^{
|
@@ -1644,7 +1737,10 @@ NSString *setKeyword = @"";
|
|
1644
1737
|
[self fireEvent:@"" event:@"on.banner.load" withData:bannerLoadJsonString];
|
1645
1738
|
|
1646
1739
|
if (auto_Show && self.bannerView) {
|
1647
|
-
|
1740
|
+
if (isSetOverlapping){
|
1741
|
+
self.bannerView.hidden = NO;
|
1742
|
+
[self setBodyHeight:command];
|
1743
|
+
}
|
1648
1744
|
} else {
|
1649
1745
|
[self fireEvent:@"" event:@"on.banner.failed.show" withData:nil];
|
1650
1746
|
}
|
@@ -1729,7 +1825,6 @@ NSString *setKeyword = @"";
|
|
1729
1825
|
}
|
1730
1826
|
}
|
1731
1827
|
|
1732
|
-
|
1733
1828
|
- (void)bannerViewDidRecordImpression:(GADBannerView *)bannerView {
|
1734
1829
|
[self fireEvent:@"" event:@"on.banner.impression" withData:nil];
|
1735
1830
|
}
|
@@ -1744,6 +1839,7 @@ NSString *setKeyword = @"";
|
|
1744
1839
|
|
1745
1840
|
- (void)bannerViewDidDismissScreen:(GADBannerView *)bannerView {
|
1746
1841
|
[self fireEvent:@"" event:@"on.banner.did.dismiss" withData:nil];
|
1842
|
+
|
1747
1843
|
}
|
1748
1844
|
|
1749
1845
|
#pragma mark GADFullScreeContentDelegate implementation
|
package/www/emiAdmobPlugin.js
CHANGED
@@ -21,6 +21,9 @@ exports.styleBannerAd = function (options, success, error) {
|
|
21
21
|
exports.loadBannerAd = function (options, success, error) {
|
22
22
|
exec(success, error, 'emiAdmobPlugin', 'loadBannerAd', [options]);
|
23
23
|
};
|
24
|
+
exports.loadBannerAdNewApi = function (options, success, error) {
|
25
|
+
exec(success, error, 'emiAdmobPlugin', 'loadBannerAdNewApi', [options]);
|
26
|
+
};
|
24
27
|
exports.showBannerAd = function (success, error) {
|
25
28
|
exec(success, error, 'emiAdmobPlugin', 'showBannerAd', []);
|
26
29
|
};
|