首页 文章

仅横向应用程序中的GameCenter身份验证会引发UIApplicationInvalidInterfaceOrientation

提问于
浏览
23

问题:如果用户未登录GameCenter帐户 - GameCenter身份验证视图以纵向模式启动(在ios 5中有一个模式对话框)要求登录 . 但如果我在xcode(项目摘要)或supportedInterfaceOrientationsForWindow中禁用纵向模式: (因为我的应用程序应该只在横向模式下运行)我得到:

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

如果我启用了ipad / iphone的肖像(和/或注释了supportedInterfaceOrientationsForWindow :)它可以正常工作而不会崩溃,但我不希望启用纵向模式 .

5 回答

  • 27

    在编写此问题并尝试使用代码时,似乎我找到了一个解决方案:在项目摘要中启用所有方向并删除应用程序:supportedInterfaceOrientationsForWindow .

    将此代码添加到ViewController:

    - (NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskLandscape;
    }
    

    现在它无缝地工作 .

  • 6

    添加到app delegate:

    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)w {
    
    return (NSUInteger)[application supportedInterfaceOrientationsForWindow:w] | (1<<UIInterfaceOrientationPortrait);
    
    }
    
  • 0

    我发现问题来自我的案例中的游戏中心 . 在模拟器中我还没有初始化游戏中心,它想要弹出登录视图,但是在纵向模式下 . 一旦达到这一点,如果我不允许纵向定位,它就会崩溃 . 作为游戏中心的操作系统中的奇怪错误应该是允许的方向只是为了与我们的横向用户界面的意图一致 .

    我还没有解决方案,但如果找到它我会发布 .

  • 1

    我和你有同样的问题,我用一个有点丑陋的工作修复它,基本上我在我的应用程序中有一个全局变量,用于选择有效的界面方向 . 在里面

    - (NSInteger)application : (UIApplication *)supportedInterfaceOrientationsForWindow:(UIWindow *)window{
              if(orientationIndicator == 1){
                   return UIInterfaceOrientationMaskAllButUpsideDown;
              }
              else if(orientationIndicator == 2){
                   return UIInterfaceOrientationMaskLandscape;
              }
         }
    

    要声明全局变量,请将其放在appDelegate.m文件中:

    int orientationIndicator = 1;
    

    要导入全局变量,请使用:

    extern int orientationIndicator;
    

    然后,您可以更改方向指示器的值,它将允许您在不同的界面类型中运行 . 所以我做的是开始使orientationIndicator = 1.当您验证播放器并启动登录视图控制器时,将方向指示器设置为2.当您关闭视图(验证播放器)时,您可以将其更改回1 .

    这是一个粘糊糊的工作,但它对我有用 .

    希望这可以帮助!

  • 0

    捕获异常似乎对我来说很好:

    @try {
        [rootNavigationController pushViewController:viewController animated:YES];
    }
    @catch (NSException *exception) {
        //somehow, catching this exception just allows the view controller to be shown?
    }
    

    在iOS 6.0中,抛出了异常,但是如果你 grab 它,那么仍然会显示viewController,并且GameCenter将在横向方向上按预期运行 .

    另一种解决方案是针对iOS 6.1及更高版本,因为Apple修复了该版本的错误 .

相关问题