1

所以,我注意到在调用 initializeGameCenter() 一次之后,每次我的应用程序回到前台时,都会调用下面的块(在 authenticateWithCompletionHandler 之后) - 这是 Game Center 的常规行为吗?(我确保放置一个断点来验证只有块被调用,而不是 initializeGameCenter 本身)

- (void)initializeGameCenter
{
    // Don't initialize Game Center unless we have access to the classes from iOS 4.1 or greater. 

    if (![self isGameCenterAvailable]) {
        return;
    }



    [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {

        NSDictionary *userInfo = nil;
        if (error == nil) {
            // Game Center will present a "Welcome Back" message when we have authenticated
            GTMLoggerInfo(@"Game Center successfully authenticated");
        }
        else {
            userInfo = [NSDictionary dictionaryWithObject:error forKey:@"NSError"];
            GTMLoggerDebug(@"error authenticating game center");
        }
        [[NSNotificationCenter defaultCenter] postNotificationName:GameCenterAuthenticateDidFinishNotification
                                                            object:self
                                                          userInfo:userInfo]; 

    }];
}
4

1 回答 1

4

来自游戏工具包编程指南:

“[当]您的游戏移回前台时,Game Kit 会对玩家进行身份验证,并调用您的身份验证处理程序。”

http://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/Users/Users.html#//apple_ref/doc/uid/TP40008304-CH8-SW11

即每次您的应用程序移动到前台时,您的完成块都会被调用,就像您调用过一样-[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:]

于 2011-03-24T10:20:18.240 回答