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

Sha*_* A. 6 ios game-center ios6

我的应用程序记录了它是否已成功通过Game Center进行身份验证.当它开始新游戏或用户查看分数列表时,如果本地播放器未成功通过身份验证,并且该应用程序当时未尝试对用户进行身份验证,则会再次尝试.

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

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

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

2012年9月25日15:54:47.829 APP NAME [1493:907] * 断言故障- [UIWindowController过渡:fromViewController:toViewController:目标:didEndSelector:],/SourceCache/UIKit/UIKit-2372/UIWindowController.m:211

然后这实际上崩溃了:

2012年9月25日15:55:25.569 APP NAME [1493:907] *终止应用程序由于未捕获的异常'NSInternalInconsistencyException',原因:"试图开始从一个模态过渡:至<GKModalRootViewController 0x1cd8b2a0> <GKHostedAuthenticateViewController:0x1e31a350>而转型已在进行中.等待viewDidAppear/viewDidDisappear知道当前的过渡已经完成了"*第一掷调用堆栈:(0x394932a3 0x31db297f 0x3949315d 0x383fd2af 0x3640377b 0x36402fcf 0x394969c4 0x393edfeb 0x36521733 0x32a83d2d 0x3264b11f 0x3264a4b7 0x3264f1bd 0x39466f3b 0x393d9ebd 0x393d9d49 0x353132eb 0x3636b301 0x7e863 0x7e808)的libc ++ abi.dylib:终止叫抛出一个例外

这是麻烦的代码:

-(void)authenticateLocalUser {

    if (!self.checkingLocalPlayer) {
        self.checkingLocalPlayer = YES;
        GKLocalPlayer *thisPlayer = [GKLocalPlayer localPlayer];

        if (!thisPlayer.authenticated) {

            [[GKLocalPlayer localPlayer]
             authenticateWithCompletionHandler:^(NSError *error)
             {
                 [self finishGameCenterAuthWithError:error];
             }
             ];
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

知道我在这里做错了吗?

小智 7

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

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

这似乎有效......

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];

    }
})];
Run Code Online (Sandbox Code Playgroud)