我正在开发一个使用游戏中心的新应用程序,但不幸的是我遇到了游戏中心身份验证问题
这是我使用的验证码:
@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");
}
}
};
}
我仔细检查了app id,排行榜标识符,我在itunes connect中启用了游戏中心,我还在View Controller.h中链接了gamekit框架和导入的游戏包,我在游戏中心启用了沙箱模式
我在OS X Mavericks上使用Xcode 5.0.2
有人可以帮忙吗?它让我疯狂!!
问候:)
答案 0 :(得分:0)
你可以使用它,我在github上为iOS游戏中心创建了一个简单的类 Easy Game Center Swift
答案 1 :(得分:0)