Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 目标C GameCenter authenticateHandler错误_Ios_Objective C_Gamekit - Fatal编程技术网

Ios 目标C GameCenter authenticateHandler错误

Ios 目标C GameCenter authenticateHandler错误,ios,objective-c,gamekit,Ios,Objective C,Gamekit,我创建了一个游戏使用。当我这样调用authenticateLocalPlayer时: 我得到一个错误: -[GKUnauthenticatedPlayerInternal name]: unrecognized selector sent to instance 0x14517e00 但当我添加[NSThread sleepForTimeInterval:1]时,如下所示: GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

我创建了一个游戏使用。当我这样调用authenticateLocalPlayer时:

我得到一个错误:

-[GKUnauthenticatedPlayerInternal name]: unrecognized selector sent to instance 0x14517e00 
但当我添加[NSThread sleepForTimeInterval:1]时,如下所示:

GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

[NSThread sleepForTimeInterval:1];
localPlayer.authenticateHandler  =
^(UIViewController *viewController, NSError *error) {

    [self setLastError:error];
    if(viewController != nil) {
        [self setAuthenticationViewController:viewController];
    } else if([GKLocalPlayer localPlayer].isAuthenticated) {
        _enableGameCenter = YES;
    } else {
        _enableGameCenter = NO;
    }
};
[self runAction:
       [SKAction sequence: @[[SKAction waitForDuration:5],
                             [SKAction performSelector: @selector(showLabel) onTarget: self]]]];

它开始运作良好。这是解决错误的正确方法吗?

我也有同样的问题。随机的睡眠并不能解决我的问题


我觉得奇怪的是,我在互联网上找不到任何其他关于这个问题的参考资料。我们不可能是唯一有这个问题的人,对吗?

我发现,对我来说,引发崩溃的原因是打电话给 [自执行选择器:@selectorshowLabel with object:nil afterDelay:5], 其中self是一个SKSpriteNode。请注意,不是在调用选择器的时候,而是在调用performSelector的时候,我发生了崩溃。还要注意的是,这个电话根本与GKLocalPlayer或游戏中心无关

解决问题的方法是使用SKAction,如下所示:

GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

[NSThread sleepForTimeInterval:1];
localPlayer.authenticateHandler  =
^(UIViewController *viewController, NSError *error) {

    [self setLastError:error];
    if(viewController != nil) {
        [self setAuthenticationViewController:viewController];
    } else if([GKLocalPlayer localPlayer].isAuthenticated) {
        _enableGameCenter = YES;
    } else {
        _enableGameCenter = NO;
    }
};
[self runAction:
       [SKAction sequence: @[[SKAction waitForDuration:5],
                             [SKAction performSelector: @selector(showLabel) onTarget: self]]]];

我真的无法解释为什么这会起作用。iOS 8.1似乎是一个不太明显的错误,因为这以前从来没有出现过问题。

关键在于不要从viewDidLoad调用启动游戏中心。如果你真的从那里打电话,请稍后再打。同意这在iOS 8.1和8.1.1中被打破,因为它以前从未出现过问题。

这似乎是iOS 8.0-8.2的问题。在我的实验中,它似乎在iOS 8.3中得到了解决。奇怪的是,我的另一款游戏的代码库似乎在整个游戏中都能正常工作,但我还没有进行详尽的测试。

我最近才意识到我的游戏有这个问题。我也不知道它的来源。我什么时候回来?我从另一边回来了!因此,我发现调用来自行localPlayer.authenicatedhandler=^UIViewController*viewController,NSError*error{}。即使块是空的,也会发生这种情况。是的,我也发现了。这似乎是苹果公司推荐的方法。所以我想知道其他人是如何做到这一点的?这只是我最近的一个游戏问题。好像是游戏中心的问题。有人找到解决方案吗?NSThread hack不适合我。你有没有找到更多关于这个的信息,或者可能是更好的黑客?