GKLocalPlayer在iOS6上使用模态转换错误进行Auth崩溃

前端之家收集整理的这篇文章主要介绍了GKLocalPlayer在iOS6上使用模态转换错误进行Auth崩溃前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用程序记录了它是否已成功通过Game Center进行身份验证.当它开始新游戏或用户查看分数列表时,如果本地播放器未成功通过身份验证,并且该应用程序当时未尝试对用户进行身份验证,则会再次尝试.

(为什么?如果您从无网络区域移动到网络区域.)

不幸的是,在iOS6 / XCode 4.5下,它开始崩溃了.或者至少在某些有限的情况下似乎:用户无法使用错误的密码和/或不存在的帐户登录.成功登录后,一切顺利.

登录失败之后,当我去做一些导致进行reauth检查的事情时,我得到了这个:

2012-09-25 15:54:47.829 APP NAME [1493:907] *
Assertion failure in -[UIWindowController
transition:fromViewController:toViewController:target:didEndSelector:],
/SourceCache/UIKit/UIKit-2372/UIWindowController.m:211

然后这实际上崩溃了:

2012-09-25 15:55:25.569 APP NAME [1493:907] *
Terminating app due to uncaught exception
‘NSInternalInconsistencyException’,reason: ‘Attempting to begin a
modal transition from <GKModalRootViewController: 0x1cd8b2a0> to
<GKHostedAuthenticateViewController: 0x1e31a350> while a transition is
already in progress. Wait for viewDidAppear/viewDidDisappear to know
the current transition has completed’
*
First throw call stack: (0x394932a3 0x31db297f 0x3949315d 0x383fd2af 0x3640377b 0x36402fcf 0x394969c4 0x393edfeb 0x36521733
0x32a83d2d 0x3264b11f 0x3264a4b7 0x3264f1bd 0x39466f3b 0x393d9ebd
0x393d9d49 0x353132eb 0x3636b301 0x7e863 0x7e808) libc++abi.dylib:
terminate called throwing an exception

这是麻烦的代码

@H_404_37@-(void)authenticateLocalUser { if (!self.checkingLocalPlayer) { self.checkingLocalPlayer = YES; GKLocalPlayer *thisPlayer = [GKLocalPlayer localPlayer]; if (!thisPlayer.authenticated) { [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) { [self finishGameCenterAuthWithError:error]; } ]; } } }

知道我在这里做错了吗?

解决方法

Ggrrrhhh同样的问题,想想我发现它… ios6已弃用authenticateWithCompletionHandler看到链接,建议你使用AuthenticateHandler.

http://developer.apple.com/library/IOS/#documentation/GameKit/Reference/GKLocalPlayer_Ref/Reference/Reference.html#//apple_ref/occ/instp/GKLocalPlayer/authenticateHandler

这似乎有效……

@H_404_37@GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; [localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller,NSError *error) { //[localPlayer authenticateWithCompletionHandler:^(NSError *error) { OLD CODE! if (localPlayer.isAuthenticated) { //do some stuff } else { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"NOT AUTHORISED" message:@"YOUR'RE NOT LOGGED INTO GC." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } })];

猜你在找的iOS相关文章