Closed amokrunner closed 6 years ago
Not sure as I have no iPhone X to test, would you try the latest version and report the result?
FWIW, if your app only uses a banner at the bottom of the screen, this change to CDVAdMob.m is enough to lift the banner into the safe area:
% diff -c CDVAdMob.m CDVAdMob2.m
*** CDVAdMob.m 2017-11-26 13:47:35.404006769 +0000
--- CDVAdMob2.m 2017-11-26 13:48:29.406648265 +0000
***************
*** 718,723 ****
--- 718,727 ----
bf.origin.x = (pr.size.width - bf.size.width) * 0.5f;
+ if (@available(iOS 11.0, *)) {
+ bf.origin.y -= self.webView.superview.safeAreaInsets.bottom;
+ }
+
self.bannerView.frame = bf;
//NSLog(@"x,y,w,h = %d,%d,%d,%d", (int) bf.origin.x, (int) bf.origin.y, (int) bf.size.width, (int) bf.size.height );
Any solution?
Just saw this, maybe it can be of some reference to whomever works this issue: https://github.com/appfeel/admob-google-cordova/pull/93/commits/0bdea388a25cb59b887b5a99847470c76097cb81
I have implemented a solution for my limited cases, may send a pull request if I find the time.
I am not able to see the banner at all on an iPhone X. Anyone find a solution to this?
@anacierdem Would you be able to post your solution? I am running into the issue of the banner not displaying at the bottom of an iPhone X but on all other iPhones.
I have changed resizeViews function in CDVAdMob.m as follows;
- (void)resizeViews {
// Frame of the main container view that holds the Cordova webview.
CGRect pr = self.webView.superview.bounds, wf = pr;
//NSLog(@"super view: %d x %d", (int)pr.size.width, (int)pr.size.height);
// iOS7 Hack, handle the Statusbar
BOOL isIOS7 = ([[UIDevice currentDevice].systemVersion floatValue] >= 7);
BOOL isIOS11 = ([[UIDevice currentDevice].systemVersion floatValue] >= 11);
CGRect sf = [[UIApplication sharedApplication] statusBarFrame];
CGFloat top = isIOS7 ? MIN(sf.size.height, sf.size.width) : 0.0;
CGFloat bottom = 0.0;
if (@available(ios 11.0, *)) {
bottom = self.webView.superview.safeAreaInsets.bottom;
}
if(! self.offsetTopBar) top = 0.0;
wf.origin.y = top;
wf.size.height = pr.size.height - top;
if( self.bannerView ) {
if( pr.size.width > pr.size.height ) {
if(GADAdSizeEqualToSize(self.bannerView.adSize, kGADAdSizeSmartBannerPortrait)) {
self.bannerView.adSize = kGADAdSizeSmartBannerLandscape;
}
} else {
if(GADAdSizeEqualToSize(self.bannerView.adSize, kGADAdSizeSmartBannerLandscape)) {
self.bannerView.adSize = kGADAdSizeSmartBannerPortrait;
}
}
CGRect bf = self.bannerView.frame;
// If the ad is not showing or the ad is hidden, we don't want to resize anything.
UIView* parentView = self.bannerOverlap ? self.webView : [self.webView superview];
BOOL adIsShowing = ([self.bannerView isDescendantOfView:parentView]) && (! self.bannerView.hidden);
if( adIsShowing ) {
//NSLog( @"banner visible" );
if( bannerAtTop ) {
if(bannerOverlap) {
wf.origin.y = top;
bf.origin.y = 0; // banner is subview of webview
} else {
bf.origin.y = top;
wf.origin.y = bf.origin.y + bf.size.height;
}
} else {
// move webview to top
wf.origin.y = top;
if( bannerOverlap ) {
bf.origin.y = wf.size.height - bf.size.height - bottom; // banner is subview of webview
} else {
bf.origin.y = pr.size.height - bf.size.height - bottom;
}
}
if(! bannerOverlap) wf.size.height -= bf.size.height;
bf.origin.x = (pr.size.width - bf.size.width) * 0.5f;
self.bannerView.frame = bf;
//NSLog(@"x,y,w,h = %d,%d,%d,%d", (int) bf.origin.x, (int) bf.origin.y, (int) bf.size.width, (int) bf.size.height );
}
}
self.webView.frame = wf;
//NSLog(@"superview: %d x %d, webview: %d x %d", (int) pr.size.width, (int) pr.size.height, (int) wf.size.width, (int) wf.size.height );
}
This is not covering all the cases but working nicely on portrait iphoneX for me. Please complete and send a pull request if you have the time
@anacierdem Thank you for sharing. I have made the changes to that file but they are not getting called. Do I need to do something special to get this code to be complied and used?
Doing cordova prepare
should update the code in the xcode project. If that doesn't work, you may try removing and adding the ios platform. Or just update the files inside platforms/ios/plugins.
Yeah, I figured out I had to edit the files in Xcode instead of a different editor. Thanks for the reply! Your update is working nicely in pushing the ad up. It just disappears when I rotate the phone from portrait to landscape. It doesn't come back when I flip it back either. Very odd.
That does not cover landscape mode, let alone rotation.
Oh jeez, okay I did not realize the complications I guess. Still trying to learn/figure out all this app business.
https://github.com/ratson/cordova-plugin-admob-free/pull/186 should address this, free feel to reopen if it does not.
Does the plugin require updating to support the iPhone X? 24 October 2017: Prepare your ads for iPhone X iPhone X Ad Rendering