Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

OpenFeint iPad screen orientation on startup?

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

  1. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    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

    Joined:
    Aug 28, 2009
    Posts:
    78
    Hi,

    I ended up working around this issue in AppController+OpenFeint.mm 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;
    3.  
    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];
    19.    
    20.     unityPaused = YES;
    21.     UnitySetAudioSessionActive(false);
    22.     UnityPause(true);
    23. }
    24.  
    25. - (void)dashboardDidDisappear
    26. {
    27.     [orientationTimer invalidate];
    28.     unityPaused = NO;
    29.     UnitySetAudioSessionActive(true);
    30.     UnityPause(false);
    31. }
    32.  
    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. }
    41.  
    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. }
    14.  
    15.  
    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.

    Cheers,
    Sean
     
  3. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    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

    ideveloper

    Joined:
    Aug 27, 2009
    Posts:
    12
    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

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    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

    ss

    Joined:
    Dec 15, 2009
    Posts:
    8
    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

    Prakash

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

    Code (csharp):
    1.  
    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. }
    14.  
    Enjoy!!!!!

    Regards,
    Prakaash
     
    Last edited: Oct 29, 2010
  8. kickerks8080

    kickerks8080

    Joined:
    Feb 23, 2010
    Posts:
    10

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

    Deleted User

    Guest

    For those still interested..

    Using OF SDK 2.10, just change AppController+Openfeint.mm (line 1033) to something like this:

    Code (csharp):
    1.  
    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. }
    13.