Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 游戏中心验证问题_Ios_Game Center_Gamekit - Fatal编程技术网

Ios 游戏中心验证问题

Ios 游戏中心验证问题,ios,game-center,gamekit,Ios,Game Center,Gamekit,我正在开发一个使用game center的新应用程序,但不幸的是,我在game center身份验证方面遇到了麻烦 以下是im使用的身份验证代码: @interface ViewController () // A flag indicating whether the Game Center features can be used after a user has been authenticated. @property (nonatomic) BOOL gameCenterEnab

我正在开发一个使用game center的新应用程序,但不幸的是,我在game center身份验证方面遇到了麻烦

以下是im使用的身份验证代码:

@interface ViewController ()



// A flag indicating whether the Game Center features can be used after a user has been authenticated.
@property (nonatomic) BOOL gameCenterEnabled;

// This property stores the default leaderboard's identifier.
@property (nonatomic, strong) NSString *leaderboardIdentifier;


@end


@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self authenticateLocalPlayer];
    _gameCenterEnabled = NO;
    _leaderboardIdentifier = @"LEADERBOARD ID HERE";
}

- (void)authenticateLocalPlayer {
    GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
    localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
        if (viewController != nil) {
            [self presentViewController:viewController animated:YES completion:nil];
        }
        else{
            if ([GKLocalPlayer localPlayer].authenticated) {
                _gameCenterEnabled = YES;
                [[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {
                    if (error != nil) {
                        NSLog(@"%@", [error localizedDescription]);
                    }
                    else{
                        _leaderboardIdentifier = leaderboardIdentifier;
                    }
                }];
            }
            else {
                _gameCenterEnabled = NO;
                NSLog(@"Game Center Not available");
            }
        }
    };
}
我仔细检查了应用程序id、排行榜标识符,我在itunes connect中启用了游戏中心,我还链接了gamekit framework,并在View Controller.h中导入了gamekit,我在game center中启用了沙箱模式

我在OSXMavericks上使用Xcode 5.0.2

有人能帮忙吗?它让我发疯


注意:)

您可以使用它,我在github中为iOS游戏中心创建了一个简单的类 简易游戏中心Swift


对于其他面临此问题的人,您需要启用游戏中心功能


为什么在“if([GKLocalPlayer].authenticated)”中打印身份验证错误。将其设为与[GKLocalPlayer]处于同一级别的else-if条件。已验证,请参阅错误描述