Ios 游戏中心-提交非默认排行榜
所以我有一个应用程序,它有一个Ios 游戏中心-提交非默认排行榜,ios,objective-c,game-center,Ios,Objective C,Game Center,所以我有一个应用程序,它有一个游戏a和游戏B 我已经为游戏A正确地实现了游戏中心(到目前为止,我在每一场游戏中都使用了相同的方法) 现在,如果玩游戏B,我很难让它提交分数。我需要将分数提交到iTunes Connect中创建的第二个排行榜 这是我的ViewController的一部分,用于验证用户并使用排行榜等的标识符 ViewController.h: -(void)authenticateLocalPlayer{ GKLocalPlayer *localPlayer = [GKLocalPl
游戏a
和游戏B
我已经为游戏A正确地实现了游戏中心(到目前为止,我在每一场游戏中都使用了相同的方法)
现在,如果玩游戏B,我很难让它提交分数。我需要将分数提交到iTunes Connect中创建的第二个排行榜
这是我的ViewController的一部分,用于验证用户并使用排行榜等的标识符
ViewController.h:
-(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; //added bool indentier to .h
// Get the default leaderboard identifier.
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
}
else{
_leaderboardIdentifier = leaderboardIdentifier; //added pointer to NSString to .h
}
}];
}
else{
_gameCenterEnabled = NO;
}
}
};
}
似乎我的游戏B视图控制器和游戏A一样是轻视/提交的,我想我可以将上面的代码更改为:(允许使用第二个标识符):
}
但由于某些原因,它不会将分数发送到第二个排行榜,我也找不到任何关于如何将分数提交到“非默认”排行榜的资源/教程…好的,所以我重新阅读了Apple文档并找到了解决方案 显然,只有一个默认排行榜(在我的问题代码中经过验证并设置)。。。这不需要像我原来想的那样改变。(我忘了它是用来设置默认板的) 因此,我需要做的是将排行榜标识符设置为第二个排行榜的标识符(这将是您在制作第二个排行榜时在iTunes Connect中使用的任何ID) 我在游戏B视图控制器中报告这样的分数时这样做:
-(void)reportScore{
//set identifier manually as it's not the default leaderboard
GKScore *score = [[GKScore alloc] initWithLeaderboardIdentifier:@"The_GameB_Leaderboard"];
//GKScore *score = [[GKScore alloc] initWithLeaderboardIdentifier:_leaderboardIdentifier2];
score.value = ScoreNumber_B; //Game B HighScore
[GKScore reportScores:@[score] withCompletionHandler:^(NSError *error) {
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
}
}];
NSLog(@"Reported to Game Center...");
}
无需更改-(void)authenticateLocalLayer
方法,除非您需要像我一样添加GameB bool
,在这种情况下,您可以将其添加到GameA bool
下面:
if ([GKLocalPlayer localPlayer].authenticated) {
_gameCenterEnabled = YES; //added bool indentier to .h
_gameCenterEnabled2 = YES; //GameB bool
.
.
.
}
我希望这有帮助
if ([GKLocalPlayer localPlayer].authenticated) {
_gameCenterEnabled = YES; //added bool indentier to .h
_gameCenterEnabled2 = YES; //GameB bool
.
.
.
}