Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MC-1709] Use keyWindow supported orientations for CTInAppDisplayViewController #340

Merged
merged 4 commits into from
Jun 26, 2024
Merged
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
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
Loading