Follow

Orientation problem on iOS with GameCenter

Symptoms

  • Calling the screen orientation changes from portrait to landscape mode, even if the project is set to use portrait mode only

Cause

If you are using the iOS presentation controller, this could override your orientation constraints. 

Resolution

As a workaround, you can modify the iOS trampoline code to use only the portrait mode.

Build for iOS and open UnityAppController.mm and replace supportedInterfaceOrientationsForWindow with the provided code:

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return (1 << UIInterfaceOrientationPortrait) | 
(0 << UIInterfaceOrientationPortraitUpsideDown) |
(0 << UIInterfaceOrientationLandscapeRight) |
(0 << UIInterfaceOrientationLandscapeLeft);
}

This article applies to Unity versions 5.3.4p3 and higher

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request

2 Comments

  • 0
    Avatar
    Harshdeep Singh

    Worked for me using Unity 5.3.3f1. Really thank a lot for this Answer :)

     

  • 0
    Avatar
    Stephan van der Feest

    Works for me in Unity 5.3.5f1.

    You can leave out the last 3 lines. They're just like doing 4 + 0 + 0 + 0 (so you can leave out the zeroes and still have the 4 left).

    - (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
    {
    return (1 << UIInterfaceOrientationPortrait);
    }

    is enough.

    Be careful of using this as a solution for landscape games not to turn portrait, though: it could end up crashing smaller iPhones when you hold the device in portrait mode and open Game Center. So test that ;)

Please sign in to leave a comment.