我正在开发一个使用游戏中心的新应用,但不幸的是我在游戏中心身份验证方面遇到了麻烦

这是即时通讯使用的身份验证代码:

@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连接中启用了游戏中心,我还链接了游戏套件框架,并在View Controller.h中导入了游戏套件,并且在游戏中心中启用了沙箱模式

我在OS X Mavericks上使用Xcode 5.0.2

有人可以帮忙吗? 它让我疯狂!

问候 :)

===============>>#1 票数:0

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

https://github.com/DaRkD0G/Easy-Game-Center-Swift

  ask by user2984696 translate from so

未解决问题?本站智能推荐: