Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Unity 2022.2 is now available as the latest Tech release.
    Dismiss Notice
  3. We are making some changes to the DOTS forums.
    Dismiss Notice
  4. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

OpenFeint iPad screen orientation on startup?

Discussion in 'iOS and tvOS' started by rocket5tim, Jun 6, 2010.

  1. rocket5tim


    May 19, 2009
    I already have my game detecting iPad orientation and rotating properly. And I have the Unity splash screen orienting to proper rotation on app startup.

    But I can't figure out how to force the OpenFeint login screen to rotate to the current orientation on app startup. It always opens according to the "Initial Dashboard Orientation" that's set in OpenFeint settings. This means if I have the iPad in the opposite orientation (upside down) when I launch the game, the OF Login screen will be displayed upside down. This is the screen that comes up immediately before/as the game starts -- apparently the login dashboard is called before any game scripts are executed so I can't even get it to check SetDashboardOrientation() before it launches.

    I'm using

    Code (csharp):
    1. OpenFeint.SetDashboardOrientation(iPhoneInput.orientation);
    before launching the Dashboard from menus inside the game so that the dashboard at least gets the proper orientation. But when the OF window is up, it doesn't rotate with the iPad.

    Any thoughts on how to handle either of the above issues?
  2. PS Neville

    PS Neville

    Aug 28, 2009

    I ended up working around this issue in by keeping track of the UIDevice orientation property and when it differs/changes from the last time I checked it, I close the OF dashboard altogether. This doesn't rotate the dashboard, but it will at least close it when it's open and the orientation changes, and Apple did approve my iPad game which employed this workaround.

    For example, here's the code for an app that uses Portrait and PortraitUpsideDown (change as needed for Landscape variants):

    Code (csharp):
    1. UIDeviceOrientation origDeviceOrientation;
    2. NSTimer *orientationTimer;
    4. // OpenFeintDelegate //
    5. - (void)dashboardWillAppear
    6. {
    7.     origDeviceOrientation = [UIDevice currentDevice].orientation;
    8.     if (origDeviceOrientation == UIDeviceOrientationPortraitUpsideDown)
    9.     {
    10.         [OpenFeint setDashboardOrientation:UIInterfaceOrientationPortraitUpsideDown];
    11.     }
    12.     else
    13.     {
    14.         [OpenFeint setDashboardOrientation:UIInterfaceOrientationPortrait];
    15.     }
    16.     orientationTimer = [NSTimer scheduledTimerWithTimeInterval:0.2f
    17.             target:self selector:@selector(checkOrientation:)
    18.             userInfo:nil repeats:YES];
    20.     unityPaused = YES;
    21.     UnitySetAudioSessionActive(false);
    22.     UnityPause(true);
    23. }
    25. - (void)dashboardDidDisappear
    26. {
    27.     [orientationTimer invalidate];
    28.     unityPaused = NO;
    29.     UnitySetAudioSessionActive(true);
    30.     UnityPause(false);
    31. }
    33. - (void) checkOrientation:(NSTimer *) theTimer
    34. {
    35.     UIDeviceOrientation dor = [UIDevice currentDevice].orientation;
    36.     if (dor != origDeviceOrientation  (dor == UIDeviceOrientationPortrait || dor == UIDeviceOrientationPortraitUpsideDown))
    37.     {
    38.         [OpenFeint dismissDashboard];
    39.     }
    40. }
    As for launching the dashboard in the correct orientation to begin with, I also used code similar to that which you referenced, but I specifically set the orientation in it.

    For example, I have the following attached to my main Camera in one of my scenes:

    Code (csharp):
    1. void FixedUpdate()
    2. {
    3.     if ((iPhoneInput.orientation == iPhoneOrientation.Portrait)  (iPhoneSettings.screenOrientation != iPhoneScreenOrientation.Portrait))
    4.     {
    5.         iPhoneSettings.screenOrientation = iPhoneScreenOrientation.Portrait;
    6.         OpenFeint.SetDashboardOrientation(iPhoneOrientation.Portrait);
    7.     }
    8.     else if ((iPhoneInput.orientation == iPhoneOrientation.PortraitUpsideDown)  (iPhoneSettings.screenOrientation != iPhoneScreenOrientation.PortraitUpsideDown))
    9.     {
    10.         iPhoneSettings.screenOrientation = iPhoneScreenOrientation.PortraitUpsideDown;
    11.        OpenFeint.SetDashboardOrientation(iPhoneOrientation.PortraitUpsideDown);
    12.     }
    13. }
    Add in the required Info.plist changes to launch in the correct orientations and the iPhoneKeyboard.autorotate* properties to prevent the outer app frame from rotating, and Apple approved the resulting behavior in my OF-enabled iPad game so although this is a workaround maybe it will also work for you.

  3. rocket5tim


    May 19, 2009
    Thanks, Sean! That's just the information I needed. Everything is working better now, tho it would be nice if there were a way to rotate OF rather than just closing it. Hopefully the OF guys will figure this out.
  4. ideveloper


    Aug 27, 2009
    Thanks a lot for the information, it really saved me some time!

    I am having a few issues thought.. I have added the following key to my Info.plist

    Code (csharp):
    1. <key>UISupportedInterfaceOrientations</key>
    2.     <array>
    3.     <string>UIInterfaceOrientationPortrait</string>
    4.     <string>UIInterfaceOrientationPortraitUpsideDown</string>
    5.     <string>UIInterfaceOrientationLandscapeLeft</string>
    6.     <string>UIInterfaceOrientationLandscapeRight</string>
    7.     </array>
    Which gets my splash screen and initial orientation to look correct. I have also added these 2 lines to my main Start() method on my game script:

    Code (csharp):
    1. iPhoneSettings.screenOrientation = (iPhoneScreenOrientation)iPhoneInput.orientation;
    2. OpenFeint.SetDashboardOrientation(iPhoneInput.orientation);
    When the application launches the splash screen looks fine, the initial game screen looks fine, but when the OF "Welcome Back" notification pops up it is upside down and comes from the bottom (instead of the top as it should). If I click the OpenFeint button to launch the dashboard the dashboard launches fine but the OS Status bar is shown upside down on the bottom of the screen. If I close the OF dashboard and then re-launch it everything looks fine. Any suggestions?
  5. rocket5tim


    May 19, 2009
    I use the following code to make my screen flip when the device is rotated and it should also make sure that the OpenFeint Dashboard and Achievement prompts are oriented properly when they display:

    Code (csharp):
    1. function FixedUpdate() {
    2.     if ((iPhoneInput.orientation == iPhoneOrientation.LandscapeLeft)  (iPhoneSettings.screenOrientation != iPhoneScreenOrientation.LandscapeLeft)){
    3.         iPhoneSettings.screenOrientation = iPhoneScreenOrientation.LandscapeLeft;
    4.         OpenFeint.SetDashboardOrientation(iPhoneOrientation.LandscapeLeft);
    5.     }
    6.     if ((iPhoneInput.orientation == iPhoneOrientation.LandscapeRight)  (iPhoneSettings.screenOrientation != iPhoneScreenOrientation.LandscapeRight)){
    7.         iPhoneSettings.screenOrientation = iPhoneScreenOrientation.LandscapeRight;
    8.         OpenFeint.SetDashboardOrientation(iPhoneOrientation.LandscapeRight);
    9.     }
    10. }
  6. ss


    Dec 15, 2009
    I've got it all working correctly thanks to you guys! - Except the OpenFeint.
    In LandscapeRight the OpenFeint "welcome back" and "dashboard" are displayed upside down?
    Any help would be greatly apprieciated...Thanks
  7. Prakash


    Oct 20, 2010
    Write the code as below and it will work…no need to close the openfient dashboard:

    Code (csharp):
    2. - (void) checkOrientation:(NSTimer *) theTimer
    3. {
    4.     origDeviceOrientation = [UIDevice currentDevice].orientation;
    5.     if (origDeviceOrientation == UIDeviceOrientationPortraitUpsideDown)
    6.     {
    7.         [OpenFeint setDashboardOrientation:UIInterfaceOrientationPortraitUpsideDown];
    8.     }
    9.     else
    10.     {
    11.         [OpenFeint setDashboardOrientation:UIInterfaceOrientationPortrait];
    12.     }
    13. }

    Last edited: Oct 29, 2010
  8. kickerks8080


    Feb 23, 2010

    Prakaash, what file do we add this code to?
  9. Deleted User

    Deleted User


    For those still interested..

    Using OF SDK 2.10, just change (line 1033) to something like this:

    Code (csharp):
    2. - (void)deviceOrientationChanged:(NSNotification*)notification
    3. {
    4.     UIInterfaceOrientation orientation = (UIInterfaceOrientation)[[UIDevice currentDevice] orientation];
    5.     if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
    6.         [OpenFeint setDashboardOrientation:orientation];
    7.     }
    8. // Original code...
    9. //  if(orientation >= UIInterfaceOrientationPortrait  orientation <= UIInterfaceOrientationLandscapeLeft) {
    10. //      [OpenFeint setDashboardOrientation:orientation];
    11. //  }
    12. }