未显示身份验证视图控制器游戏套件 ios 7



>我在ios 7上,使用以下代码:

-(IBAction)authenticateLocalPlayerWithViewController
{
    GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
    __weak GKLocalPlayer *blockLocalPlayer = localPlayer;
    localPlayer.authenticateHandler = ^(UIViewController *receivedViewController, NSError *error){
        if (receivedViewController != nil)
        {
            [self presentViewController:receivedViewController animated:YES completion:nil];
        } else if (blockLocalPlayer.isAuthenticated) {
            signinButton.hidden = YES;
            leaderboardButton.alpha = 1.0;
            leaderboardButton.enabled = YES;
            achievementsButton.alpha = 1.0;
            achievementsButton.enabled = YES;

            NSString *identifier;
            [self reportAchievement1Identifier:identifier percentComplete:((interactiveHighscore/10000)*100.0)];
            [self reportAchievement2Identifier:identifier percentComplete:((interactiveHighscore/100000)*100.0)];
            [self reportAchievement3Identifier:identifier percentComplete:((interactiveHighscore/1000000)*100.0)];
            [self reportAchievement4Identifier:identifier percentComplete:((interactiveHighscore/100000000)*100.0)];
            [self reportAchievement5Identifier:identifier percentComplete:((allCoins/100000)*100.0)];
            [self submitMyInteractiveScore];
            [self submitMyNormalScore];
            BOOL isRunMoreThanOnceGC = [[NSUserDefaults standardUserDefaults] boolForKey:@"isRunMoreThanOnceGC"];
            if (!isRunMoreThanOnceGC) {
                UIAlertView *alert = [[UIAlertView alloc]
                                      initWithTitle:@"Game Center Sign In Gift"
                                      message:@"Thanks for signing in with game center here is 50 Coins."
                                      delegate:nil
                                      cancelButtonTitle:@"Thanks!."
                                      otherButtonTitles:nil];
                [alert show];
                allCoins = [[NSUserDefaults standardUserDefaults] integerForKey:@"allCoins"];
                allCoins += 50;
                [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isRunMoreThanOnceGC"];
                [[NSUserDefaults standardUserDefaults] synchronize];

            }
        } else {
            signinButton.hidden = NO;
            UIAlertView *alert = [[UIAlertView alloc]
                                  initWithTitle:@"Game Center Not Available"
                                  message:@"Uh Oh! Seems there was an error trying to sign in for Game Center. Try logging in through the Game Center app."
                                  delegate:nil
                                  cancelButtonTitle:@"Ok, Thanks."
                                  otherButtonTitles:nil];
            [alert show];
        }
        NSLog(@"Error: %d", [error code]);
    };
}

正在尝试对用户进行身份验证。首先在根控制器的视图DidLoad 上,我用这个来调用它:

//get game center
LeaderboardsViewController *LVC = [[LeaderboardsViewController alloc] init];
[LVC authenticateLocalPlayerWithViewController];

然后我得到这个:

错误: 0警告:尝试显示其视图不在窗口层次结构中!

所以我尝试按下gamecenterviewcontroller类中的按钮(这就是身份验证方法所在的地方),但我什么也得不到。日志中没有任何内容,也没有显示任何内容。

运行 ios 7 GM 构建。

多谢!

必须在同一类中重新创建该方法。 无法从外部类显示视图控制器/

最新更新