Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Multiple iPhone X & iOs11 Fixes #232

Merged
merged 8 commits into from
Jun 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ios/CDVAdMob.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import <Cordova/CDV.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Cordova/CDVPlugin.h>

#import <GoogleMobileAds/GADAdSize.h>
#import <GoogleMobileAds/GADBannerView.h>
Expand All @@ -23,8 +24,9 @@

// This version of the AdMob plugin has been tested with Cordova version 2.5.0.


@interface CDVAdMob : CDVPlugin <GADBannerViewDelegate, GADInterstitialDelegate, GADRewardBasedVideoAdDelegate> {
@protected
UIView* _safeAreaBackgroundView;
}

@property(nonatomic, retain) GADBannerView *bannerView;
Expand Down
61 changes: 53 additions & 8 deletions src/ios/CDVAdMob.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#import "MainViewController.h"



@interface CDVAdMob()

- (void) __setOptions:(NSDictionary*) options;
Expand Down Expand Up @@ -107,6 +106,8 @@ - (void)pluginInitialize {
rewardedVideoLock = nil;

srand((unsigned int)time(NULL));

[self initializeSafeAreaBackgroundView];
}

- (void) setOptions:(CDVInvokedUrlCommand *)command {
Expand Down Expand Up @@ -531,7 +532,7 @@ - (void) __createBanner {
NSLog(@"__createBanner");

// set background color to black
self.webView.superview.backgroundColor = [UIColor blackColor];
//self.webView.superview.backgroundColor = [UIColor blackColor];
//self.webView.superview.tintColor = [UIColor whiteColor];

if (!self.bannerView){
Expand Down Expand Up @@ -663,17 +664,42 @@ - (void) __showRewardedVideo:(BOOL)show {
}
}

- (void) initializeSafeAreaBackgroundView
{
if (@available(iOS 11.0, *)) {

UIView* parentView = self.bannerOverlap ? self.webView : [self.webView superview];
CGRect pr = self.webView.superview.bounds;

CGRect safeAreaFrame = CGRectMake(0, 0, 0, 0);

safeAreaFrame.origin.y = pr.size.height - parentView.safeAreaInsets.bottom;
safeAreaFrame.size.width = pr.size.width;
safeAreaFrame.size.height = parentView.safeAreaInsets.bottom;


_safeAreaBackgroundView = [[UIView alloc] initWithFrame:safeAreaFrame];
_safeAreaBackgroundView.backgroundColor = [UIColor blackColor];
_safeAreaBackgroundView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin);
_safeAreaBackgroundView.autoresizesSubviews = YES;
_safeAreaBackgroundView.hidden = true;

[self.webView.superview addSubview:_safeAreaBackgroundView];
}
}

- (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) && ([[UIDevice currentDevice].systemVersion floatValue] < 11);
CGRect sf = [[UIApplication sharedApplication] statusBarFrame];
CGFloat top = isIOS7 ? MIN(sf.size.height, sf.size.width) : 0.0;
//BOOL isIOS7 = ([[UIDevice currentDevice].systemVersion floatValue] >= 7);
//CGRect sf = [[UIApplication sharedApplication] statusBarFrame];
//CGFloat top = isIOS7 ? MIN(sf.size.height, sf.size.width) : 0.0;
float top = 0.0;

if(! self.offsetTopBar) top = 0.0;
//if(! self.offsetTopBar) top = 0.0;

wf.origin.y = top;
wf.size.height = pr.size.height - top;
Expand Down Expand Up @@ -719,6 +745,18 @@ - (void)resizeViews {
bf.origin.y -= parentView.safeAreaInsets.bottom;
bf.size.width = wf.size.width - parentView.safeAreaInsets.left - parentView.safeAreaInsets.right;
wf.size.height -= parentView.safeAreaInsets.bottom;

//If safeAreBackground was turned turned off, turn it back on
_safeAreaBackgroundView.hidden = false;


CGRect saf = _safeAreaBackgroundView.frame;
saf.origin.y = pr.size.height - parentView.safeAreaInsets.bottom;
saf.size.width = pr.size.width;
saf.size.height = parentView.safeAreaInsets.bottom;

_safeAreaBackgroundView.frame = saf;
_safeAreaBackgroundView.bounds = saf;
}
}
}
Expand All @@ -731,15 +769,22 @@ - (void)resizeViews {
self.bannerView.bounds = 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 );
}
} else {
//Hide safe area background if visibile and banner ad does not exist
_safeAreaBackgroundView.hidden = true;
}
} else {
//Hide safe area background if visibile and banner ad does not exist
_safeAreaBackgroundView.hidden = true;
}

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 );
}

- (void)deviceOrientationChange:(NSNotification *)notification {
- (void)deviceOrientationChange:(NSNotification *)notification {

[self resizeViews];
}

Expand Down