0

这真让我抓狂。每次我尝试使用 Game Center 对本地玩家进行身份验证时,我都会得到一个 thread-1 sigkill。localPlayer在我像这样设置之后它异步发生authenticateHandler

- (void)authenticateLocalPlayer
{
    if([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
    {
        GKLocalPlayer __weak *localPlayer = [GKLocalPlayer localPlayer];
        localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
        {
            if (viewController != nil)
            {
                [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:viewController animated:YES completion:nil];
            }
            else if (localPlayer.isAuthenticated)
            {
                NSLog(@"Player authenticated");
            }
            else
            {
                NSLog(@"Player authentication failed");
            }
        };
    }
}

有任何想法吗?

4

3 回答 3

0

尝试把__weak之前GKLocalPlayer

这是我在您的代码和我使用的代码之间看到的唯一区别......

于 2014-07-29T02:49:20.657 回答
0

[GKLocalPlayer localPlayer] returns a singleton and __weak releases it at some time (I don't understand when that happens, but at some future time). localPlayer might be getting released, along with the block, before the block finishes executing. There's no need to release a singleton. Try removing __weak.

于 2013-08-10T01:38:43.067 回答
0

我经常看到使用字符串比较而不是数字比较来测试 systemVersion。尝试只打印的值

[[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0

验证该表达式没有问题。我知道以下方法有效:

-(BOOL) os6 {
    NSString *targetSystemVersion = @"6.0";
    NSString *currentSystemVersion = [[UIDevice currentDevice] systemVersion];
    if ([currentSystemVersion compare:targetSystemVersion options:NSNumericSearch] == NSOrderedAscending) {
        return NO;  //current system version is less than 6.0
    } else {
        return YES;
    }
}
于 2013-08-08T18:29:44.117 回答