我有以下代码来验证GameKit中的本地用户。没有诊断也没有崩溃,但从不使用处理程序,并且从不对本地用户进行身份验证。有人可以说为什么?这种身份验证方式遵循Cocos2d上的Wenderlich博客。 ANNOUNCE和CCLOG行是我的调试方法,它们显示调用该方法但不调用处理程序。冗余外观的BOOL也来自调试。我在iOS6 iPhone上测试。此代码位于AppDelegate中。
-(void) authenticateLocalPlayer {
ANNOUNCE
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) {
[self setLastError:error];
if ( [CCDirector sharedDirector].isPaused ) [[CCDirector sharedDirector] resume];
CCLOG(@"inside authenticateHandler");
if (localPlayer.authenticated) {
_gameCenterFeaturesEnabled = YES;
X.localPlayerAuthenticated = YES;
} else if (viewController) {
[[CCDirector sharedDirector] pause];
[self presentViewController:viewController];
} else {
_gameCenterFeaturesEnabled = NO;
X.localPlayerAuthenticated = NO;
}
};
CCLOG(@"lastError: %@", self.lastError);
CCLOG(@"localPlayer.authenticated: %d", localPlayer.authenticated);
}