游戏中心仅在i OS 6中登录

Min*_*ias 20 iphone uiinterfaceorientation game-center ios6

加载游戏中心时,其默认方向为纵向.为了将其锁定在横向模式中,添加了一个类别.

@implementation GKMatchmakerViewController (LandscapeOnly)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return ( interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate {
    return NO;
}
@end
Run Code Online (Sandbox Code Playgroud)

它在iOS 6下面工作正常.但在iOS6中显示错误.

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

请解释一下解决方案.

Min*_*ias 39

最后,我通过遵循Apple iOS 6 发行说明中提到的解决方法避免了崩溃.

解决方法:

1.Apps should provide the delegate method application:supportedIntefaceOrientationsForWindow and ensure that portrait is one of the returned mask values.

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

    return UIInterfaceOrientationMaskAllButUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)

2.当涉及UIBNavigationController(或UIViewController)时,继承UINavigationController/UIViewController并覆盖supportedInterfaceOrientations.

 - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscape;
    }
Run Code Online (Sandbox Code Playgroud)

In buid summary supported orientations selected landscape right and landscape left.

现在游戏中心正常运行而不会崩溃.