Game Center authentication error

China☆狼群 提交于 2019-12-30 07:03:13

问题


I'm trying to call the authentication method of game center, however no authentication screen comes up and the callback return with an error : "the requested operation has been canceled".

The code :

[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error)
     {
        NSDictionary *userInfo = nil;
        if (error == nil) {

            NSLog(@"Game Center successfully authenticated");
        }
        else {
            userInfo = [NSDictionary dictionaryWithObject:error forKey:@"NSError"];
        }
        [[NSNotificationCenter defaultCenter] postNotificationName:Notification
                                                            object:self
                                                          userInfo:userInfo];

    }];

Any idea what can cause this issue ?


回答1:


In iOS 4.2 when a user cancels the login to Game Center, after 3 attempts that error is returned. You can resolve the error by logging in using the Game Center app, then try your app again, you should see the welcome back message from Game Center in your app




回答2:


You should do something like that after you have tested if game center is available on the specific device:

GKLocalPlayer *localplayer = [GKLocalPlayer localPlayer];
[localplayer authenticateWithCompletionHandler:^(NSError *error) {
    if (error) {
        //DISABLE GAME CENTER FEATURES / SINGLEPLAYER
    }
    else {
        //ENABLE GAME CENTER FEATURES / MULTIPLAYER
    }
}];


来源:https://stackoverflow.com/questions/4386321/game-center-authentication-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!