Skip to content

Commit 119f0c3

Browse files
committed
[iOS] Hotfix banner ad lost top position after interstitial ad.
1 parent 546bc1a commit 119f0c3

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

Plugins/iOS/CASUView.m

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ @implementation CASUView {
2424
int _activeSizeId;
2525
BOOL _requiredRefreshSize;
2626
BOOL _adHidden;
27-
27+
2828
/// Bug in Apple's SKProductViewController which always tries to present in portrait mode.
2929
/// In landscape apps, it tries to force the orientation to be portrait, causing the safe areas insets to switch to portrait mode insets even though the SKProductViewController looks like it's presenting in landscape.
3030
/// As woraround we ignore Top safearea offset if Portrait Orientation is not Supported.
@@ -76,8 +76,7 @@ - (void)enable {
7676
return;
7777
}
7878

79-
UIWindow *unityWindow = [CASUPluginUtil unityWindow];
80-
UIViewController *unityController = unityWindow.rootViewController;
79+
UIViewController *unityController = [CASUPluginUtil unityWindow].rootViewController;
8180

8281
self.bannerView = [[CASBannerView alloc] initWithCasID:_casID
8382
size:[self getSizeByCode:_activeSizeId]
@@ -114,7 +113,7 @@ - (void)enable {
114113
attribute:NSLayoutAttributeTop
115114
relatedBy:NSLayoutRelationGreaterThanOrEqual
116115
toItem:_isPortraitOrientationSupported ?
117-
safeArea : unityWindow
116+
safeArea : unityView
118117
attribute:NSLayoutAttributeTop
119118
multiplier:1.0
120119
constant:0.0],
@@ -141,7 +140,7 @@ - (void)enable {
141140
constant:0.0]
142141
]];
143142

144-
[self refreshPositionInSafeArea:safeArea];
143+
[self refreshPosition];
145144
}
146145

147146
- (void)destroy {
@@ -192,8 +191,7 @@ - (void)setPositionCode:(int)code withX:(int)x withY:(int)y {
192191
_verticalOffset = y;
193192

194193
if (self.bannerView) {
195-
UILayoutGuide *safeArea = self.bannerView.superview.safeAreaLayoutGuide;
196-
[self refreshPositionInSafeArea:safeArea];
194+
[self refreshPosition];
197195
}
198196
}
199197

@@ -341,7 +339,14 @@ - (CGSize)getSafeAreaSize {
341339
}
342340

343341
/// Attention. NSLayoutConstraint with `[self getWindow].safeAreaLayoutGuide` can be lost (removed) after Window refreshed (Interstitial ad), use `superview.safeAreaLayoutGuide` instead.
344-
- (void)refreshPositionInSafeArea:(UILayoutGuide *)safeArea {
342+
- (void)refreshPosition {
343+
if (!self.bannerView) {
344+
return;
345+
}
346+
347+
UIView *superView = self.bannerView.superview;
348+
UILayoutGuide *safeArea = superView.safeAreaLayoutGuide;
349+
345350
if (!safeArea) {
346351
return;
347352
}
@@ -354,7 +359,7 @@ - (void)refreshPositionInSafeArea:(UILayoutGuide *)safeArea {
354359
case kCASUPosition_TOP_CENTER:
355360
case kCASUPosition_TOP_LEFT:
356361
case kCASUPosition_TOP_RIGHT:{
357-
self.constraintY = [NSLayoutConstraint constraintWithItem:self.bannerView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem: _isPortraitOrientationSupported ? safeArea : [CASUPluginUtil unityWindow] attribute:NSLayoutAttributeTop multiplier:1.0 constant:_verticalOffset];
362+
self.constraintY = [NSLayoutConstraint constraintWithItem:self.bannerView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_isPortraitOrientationSupported ? safeArea : superView attribute:NSLayoutAttributeTop multiplier:1.0 constant:_verticalOffset];
358363
break;
359364
}
360365

0 commit comments

Comments
 (0)