游戏中心认证问题

7

我已经更新了游戏中心玩家认证的方式,但是在启动时仍然出现崩溃。

这是我进行认证的新方法:

- (void) authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
    if (viewController != nil)
    {
        NSLog (@"user not logged in to GC");
    }
    else if ([GKLocalPlayer localPlayer].isAuthenticated)
    {
        NSLog(@"gamecenter authentication process succeeded");
    }
    else
    {
        NSLog(@"user not authenicated");
    }
};
}

当它崩溃时,会显示以下内容:

2014-11-12 16:20:43.295 ZombieConga[7492:881764] -[GKLocalPlayerInternal name]: unrecognized       selector sent to instance 0x7974b8c0
2014-11-12 16:20:43.298 ZombieConga[7492:881764] *** Terminating app due to uncaught     exception 'NSInvalidArgumentException', reason: '-[GKLocalPlayerInternal name]: unrecognized   selector sent to instance 0x7974b8c0'
*** First throw call stack:
(
0   CoreFoundation                      0x01ef6946 __exceptionPreprocess + 182
1   libobjc.A.dylib                     0x01b8ea97 objc_exception_throw + 44
2   CoreFoundation                      0x01efe5c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3   CoreFoundation                      0x01e473e7 ___forwarding___ + 1047
4   CoreFoundation                      0x01e46fae _CF_forwarding_prep_0 + 14
5   SpriteKit                           0x01a20f82 -[SKNode isEqual:] + 124
6   Foundation                          0x015f5612 +[NSObject(NSDelayedPerforming) cancelPreviousPerformRequestsWithTarget:] + 345
7   GameCenterFoundation                0x0b1ef11e -[GKPlayer postChangeNotification] + 45
8   GameCenterFoundation                0x0b209aa8 __52-[GKDaemonProxy setLocalPlayer:authenticated:reply:]_block_invoke + 922
9   libdispatch.dylib                   0x0237a30a _dispatch_call_block_and_release + 15
10  libdispatch.dylib                   0x0239ae2f _dispatch_client_callout + 14
11  libdispatch.dylib                   0x0238190e _dispatch_main_queue_callback_4CF + 606
12  CoreFoundation                      0x01e5095e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
13  CoreFoundation                      0x01e0f760 __CFRunLoopRun + 2256
14  CoreFoundation                      0x01e0ebcb CFRunLoopRunSpecific + 443
15  CoreFoundation                      0x01e0e9fb CFRunLoopRunInMode + 123
16  GraphicsServices                    0x036dc24f GSEventRunModal + 192
17  GraphicsServices                    0x036dc08c GSEventRun + 104
18  UIKit                               0x0019f8b6 UIApplicationMain + 1526
19  ZombieConga                         0x000f898d main + 141
20  libdyld.dylib                       0x023c6ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

为什么会崩溃?

添加一个所有异常断点,您将获得更好的错误描述。 - dragoneye
@dragoneye 当我这样做时,我得到的只有:2014-11-13 00:17:39.341 ZombieConga[7990:971858] -[GKLocalPlayerInternal name]: 无法识别的选择器发送到实例0x7a920770。 - user3593148
请查看此链接:https://dev59.com/0IPba4cB1Zd3GeqPpj50。 - dragoneye
你有找到什么吗?我也遇到了同样的问题。 - erdekhayser
@erdekhayser,我找到了答案,也许对你有用。 - user3593148
1个回答

2
我的游戏解决方案非常奇怪(我自己也不完全理解)。通过将对[self authorizeLocalPlayer]的调用移动到生命周期的较后阶段,例如在我首次初始化SKScene时,而不是在-(void)viewDidLoad早期,可以防止此崩溃。
我认为这与线程有关,但我不能确定。我对代码进行了一些看似无关的更改,涉及多线程,导致它再次出现问题(我不得不将一个调用更改为performSelector:withObject:afterDelay:[NSTimer scheduledTimerWith...])。
基本上,这是一个很难追踪的问题,需要进行一些操作。抱歉我不能更具体 :(

我在我的主菜单场景中使用了performSelector:withobject:afterdelay方法,这是第一个加载的场景。通过将其移除,现在它可以正常工作。由于某种原因,这就是导致崩溃的原因。 - user3593148
@user3593148 花了一段时间才解决了这个问题,因为谁能想到 perform selector 会导致它呢?它们似乎是不相关的。 - erdekhayser

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接