From cfe4b64aea051aa99e9bef3b778d68a328c66e4d Mon Sep 17 00:00:00 2001 From: emawby Date: Thu, 23 Sep 2021 12:08:17 -0700 Subject: [PATCH] Manually controlling supportedInterfaceOrientations for IAMs --- .../Source/OSInAppMessageViewController.m | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.m b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.m index f1af98199..3d13ede28 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.m +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.m @@ -722,6 +722,40 @@ - (void)jsEventOccurredWithBody:(NSData *)body { } } +/* + Unity overrides orientation behavior and enables all orientations in supportedInterfaceOrientations, regardless of + the values set in the info.plist. It then uses its own internal logic for restricting the Application's views to + the selected orientations. This view controller inherits the behavior of all orientations being allowed so we need + to manually set the supported orientations based on the values in the plist. + If no values are selected for the orientation key in the plist then we will default to super's behavior. +*/ +- (UIInterfaceOrientationMask)supportedInterfaceOrientations { + NSUInteger orientationMask = 0; + NSArray *supportedOrientations = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"]; + if (!supportedOrientations) { + return [super supportedInterfaceOrientations]; + } + + if ([supportedOrientations containsObject:@"UIInterfaceOrientationLandscapeLeft"]) { + orientationMask += UIInterfaceOrientationMaskLandscapeLeft; + } + + if ([supportedOrientations containsObject:@"UIInterfaceOrientationLandscapeRight"]) { + orientationMask += UIInterfaceOrientationMaskLandscapeRight; + } + + if ([supportedOrientations containsObject:@"UIInterfaceOrientationPortrait"]) { + orientationMask += UIInterfaceOrientationMaskPortrait; + } + + if ([supportedOrientations containsObject:@"UIInterfaceOrientationPortraitUpsideDown"]) { + orientationMask += UIInterfaceOrientationMaskPortraitUpsideDown; + } + + return orientationMask; + +} + /* Override method for handling orientation change within a view controller on iOS 8 or higher This specifically handles the resizing and reanimation of a currently showing IAM