Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 仅横向应用程序中的GameCenter身份验证抛出UIApplicationInvalidInterfaceOrientation_Ios_Orientation_Ios6_Landscape_Game Center - Fatal编程技术网

Ios 仅横向应用程序中的GameCenter身份验证抛出UIApplicationInvalidInterfaceOrientation

Ios 仅横向应用程序中的GameCenter身份验证抛出UIApplicationInvalidInterfaceOrientation,ios,orientation,ios6,landscape,game-center,Ios,Orientation,Ios6,Landscape,Game Center,问题: 如果用户未登录GameCenter帐户-GameCenter身份验证视图以纵向模式启动(在ios 5中有一个模式对话框),请求登录。但如果我在xcode(项目摘要)或SupportedInterfaceOrientionsforWindow中禁用纵向模式:(因为我的应用程序应该只在横向模式下运行),我会得到: 由于未捕获的异常“UIApplicationInvalidInterfaceOrientation”而终止应用程序,原因是:“受支持的方向与应用程序没有共同的方向,并且should

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

由于未捕获的异常“UIApplicationInvalidInterfaceOrientation”而终止应用程序,原因是:“受支持的方向与应用程序没有共同的方向,并且shouldAutorotate正在返回YES”


如果我为ipad/iphone启用肖像(和/或注释掉支持的InterfaceOrientionsforWindow:),它不会崩溃,但我不希望启用肖像模式

在写这个问题和尝试代码时,我似乎找到了一个解决方案: 在项目摘要中启用所有方向,并删除application:SupportedInterfaceOrientionsForWindow

将此代码添加到ViewController:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

现在它可以无缝工作。

我发现问题来自游戏中心。当在模拟器中我还没有初始化游戏中心时,它会弹出登录视图,但处于纵向模式。一旦达到这一点,如果我不允许纵向,它就会崩溃。作为游戏中心的操作系统中的奇怪bug应该采取允许的方向,只是为了符合我们的横向用户界面意图

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

添加到应用程序委派:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)w {

return (NSUInteger)[application supportedInterfaceOrientationsForWindow:w] | (1<<UIInterfaceOrientationPortrait);

}
-(NSUInteger)应用程序:(UIApplication*)应用程序支持的InterfaceDirectionsforWindow:(UIWindow*)w{

return(nsuiger)[application supportedInterfaceOrientionsforWindow:w]|(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;
然后,您可以更改方向指示器的值,它将允许您在不同的界面类型中运行。因此,我所做的是首先将方向指示器设置为1。当您验证播放机并启动登录视图控制器时,将方向指示器设置为2。当您关闭视图时(验证播放机)然后你可以把它改回1

这是一个肮脏的工作,但它已经为我工作


希望这有帮助!

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

@try {
    [rootNavigationController pushViewController:viewController animated:YES];
}
@catch (NSException *exception) {
    //somehow, catching this exception just allows the view controller to be shown?
}
在iOS 6.0中,会引发异常,但如果捕捉到该异常,则仍会显示viewController,GameCenter将按预期在横向方向运行


另一种解决方案是只针对iOS 6.1及以上版本,因为苹果在该版本中修复了该漏洞。

我知道你已经找到了一个解决方法,但这听起来像是一个漏洞,你应该将其提交给苹果。这是一个已知的问题,详细内容见游戏中心。有正式的解决方法吗?具体如何?也许你忘记了什么?摘要?或者是y你有很多视图(而我只有一个,因为我的应用程序使用opengl视图)?这个解决方案好一点:你应该仔细阅读。两者都允许应用程序肖像,但在主视图中拒绝。唯一的区别——在appdelegate代码或在Project->Summary中——几乎是一样的。奇怪的是Minna说我的解决方法不起作用,但我认为邪恶的根源在于遗忘视图::supportedInterface方向。在我的模拟器(xcode 4.5)中,这两种方法都可以工作。它确实可以工作,但当我站在纵向位置开始游戏时,它没有正确旋转(游戏认为它是横向的),但旋转任何一种方式都可以使它正确显示。它仅用于横向左侧和横向右侧。解决方案@jonathanpeppers链接到()在我的情况下效果更好。此解决方案修复了ios 6中的问题,但在ios 5下我的应用程序中导致方向异常(我认为这与激活项目摘要中的所有方向相关)。另一方面,链接的解决方案似乎解决了这些问题,还有一个额外的优势,就是在摘要中显示了正确的方向。(最后一个注意事项:如果实施了其他解决方案,请阅读下面的我的评论)。是的,就像在文章标题中写的一样,问题出现在“仅在横向环境中的GameCenter身份验证”中。在ios6中,GC似乎没有针对iphone的auth screen的横向资源,所以我怀疑你找不到真正的解决方案-这里只介绍了解决方法。这就是为什么当GC需要时,你必须允许应用程序以纵向模式启动-但如果你当然不需要纵向,那么在主视图中拒绝纵向。顺便说一句,没有这样的解决方案ios6上的ipad出现问题。