Skip to content

Commit

Permalink
[MC-1709] Use keyWindow supported orientations for CTInAppDisplayView…
Browse files Browse the repository at this point in the history
…Controller (#340)

* Supported orientations based on the window orientations

* Use keyWindow
  • Loading branch information
nzagorchev authored Jun 26, 2024
1 parent 2b147be commit 61a6ce1
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions CleverTapSDK/CTInAppDisplayViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,55 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIVi

#if !(TARGET_OS_TV)
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
UIWindow *window = [CTUIUtils getKeyWindow];
UIInterfaceOrientationMask windowSupportedOrientations = [[CTUIUtils getSharedApplication] supportedInterfaceOrientationsForWindow:window];

if (_notification.hasPortrait && _notification.hasLandscape) {
return UIInterfaceOrientationMaskAll;
} else if (_notification.hasPortrait) {
return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown);
} else if (_notification.hasLandscape) {
return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight);
} else {
return UIInterfaceOrientationMaskAll;
return windowSupportedOrientations;
}
if (_notification.hasPortrait) {
if ([self isOrientationSupported:UIInterfaceOrientationPortrait mask:windowSupportedOrientations]
&& [self isOrientationSupported:UIInterfaceOrientationPortraitUpsideDown mask:windowSupportedOrientations]) {
return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown);
}
if ([self isOrientationSupported:UIInterfaceOrientationPortrait mask:windowSupportedOrientations]) {
return UIInterfaceOrientationMaskPortrait;
}
if ([self isOrientationSupported:UIInterfaceOrientationPortraitUpsideDown mask:windowSupportedOrientations]) {
return UIInterfaceOrientationMaskPortraitUpsideDown;
}
return windowSupportedOrientations;
}
if (_notification.hasLandscape) {
if ([self isOrientationSupported:UIInterfaceOrientationLandscapeLeft mask:windowSupportedOrientations]
&& [self isOrientationSupported:UIInterfaceOrientationLandscapeRight mask:windowSupportedOrientations]) {
return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight);
}
if ([self isOrientationSupported:UIInterfaceOrientationLandscapeLeft mask:windowSupportedOrientations]) {
return UIInterfaceOrientationMaskLandscapeLeft;
}
if ([self isOrientationSupported:UIInterfaceOrientationLandscapeRight mask:windowSupportedOrientations]) {
return UIInterfaceOrientationMaskLandscapeRight;
}
return windowSupportedOrientations;
}
return windowSupportedOrientations;
}

- (BOOL)isOrientationSupported:(UIInterfaceOrientation)orientation mask:(UIInterfaceOrientationMask)mask {
switch (orientation) {
case UIInterfaceOrientationPortrait:
return (mask & UIInterfaceOrientationMaskPortrait) != 0;
case UIInterfaceOrientationPortraitUpsideDown:
return (mask & UIInterfaceOrientationMaskPortraitUpsideDown) != 0;
case UIInterfaceOrientationLandscapeLeft:
return (mask & UIInterfaceOrientationMaskLandscapeLeft) != 0;
case UIInterfaceOrientationLandscapeRight:
return (mask & UIInterfaceOrientationMaskLandscapeRight) != 0;
default:
return NO;
}
}
#endif

- (void)show:(BOOL)animated {
Expand Down

0 comments on commit 61a6ce1

Please sign in to comment.