iOS 6游戏中心崩溃的身份验证 [英] iOS 6 Game Center Crash on Authentication
问题描述
我在Cocos2d-iPhone中构建一个游戏,当我更新到iOS 6时,我注意到苹果改变了Game Center身份验证的方式,使用 authenticateHandler
而不是 authenticateWithCompletionHandler
。
我添加了新的身份验证方法,但如果玩家尚未登录游戏中心,游戏现在会崩溃。如果用户已经登录,没有问题。
这是我的代码:
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@6.0))
{
GKLocalPlayer * localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController * viewController,NSError * error)
{
if(viewController!= nil)
{
AppController * appDelegate = )[UIApplication sharedApplication] .delegate;
[delegate.viewController presentViewController:viewController animated:YES completion:nil];
}
else if(localPlayer.isAuthenticated)
{
NSLog(@Player authenticated);
}
else
{
NSLog(@Player authentication failed);
}
};
}
看起来像在试图呈现Game Center viewController时崩溃,我使用完全相同的代码来呈现 GKTurnBasedMatchmakerViewController
没有问题。
任何帮助将非常感谢。 / p>
编辑:
以下是在崩溃时抛出的异常:
未捕获异常UIApplicationInvalidInterfaceOrientation:支持的方向与应用程序没有通用方向,shouldAutorotate正在返回YES
在这里你可以找到有关崩溃的有用信息,我认为这是根本原因。
https://developer.apple.com/library /ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html
应用程式应提供委托方法应用程式:supportedIntefaceOrientationsForWindow,并确保肖像是
$ bcode> - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
I am building a game in Cocos2d-iPhone, and while I was updating to iOS 6, I noticed that Apple changed the way Game Center authentication is done, using authenticateHandler
instead of authenticateWithCompletionHandler
.
I added the new authentication method, but the game now crashes if a player is not already logged in to Game Center. There is no problem authenticating if a user is already logged in.
Here is my code:
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
{
if (viewController != nil)
{
AppController *appDelegate = (AppController*)[UIApplication sharedApplication].delegate;
[delegate.viewController presentViewController:viewController animated:YES completion:nil];
}
else if (localPlayer.isAuthenticated)
{
NSLog(@"Player authenticated");
}
else
{
NSLog(@"Player authentication failed");
}
};
}
It seems like it's crashing when trying to present the Game Center viewController, even though I use the exact same code to present the GKTurnBasedMatchmakerViewController
with no issues.
Any help would be much appreciated.
EDIT: Here is the exception getting thrown on crash:
Uncaught Exception UIApplicationInvalidInterfaceOrientation: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES
Here you can find useful information about your crash, I think it is the underlying reason. https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html
Apps should provide the delegate method application:supportedIntefaceOrientationsForWindow and ensure that portrait is one of the returned mask values.
I added below code to fix this crash.
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
这篇关于iOS 6游戏中心崩溃的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!