所以我的应用程序有Game A
和Game B
。
我已经为游戏A正确实施了游戏中心(到目前为止我使用AppCoda tutorial就像我对每场比赛一样。)
现在,如果玩游戏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一样是scorings / submitting,我想我可以将上面的代码更改为:(允许第二个标识符):
-(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
_gameCenterEnabled2 = YES;
// 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
}
}];
// Get the second leaderboard identifier.
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier2, NSError *error) {
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
}
else{
_leaderboardIdentifier2 = leaderboardIdentifier2; //added pointer to NSString to .h
}
}];
}
else{
_gameCenterEnabled = NO;
_gameCenterEnabled2 = NO;
}
}
};
}
但出于某种原因,它不会将分数发送到第二个排行榜,我无法找到有关如何将分数提交到非默认&#34的任何资源/教程;排行榜...
答案 0 :(得分:0)
好的,我重读了Apple Doc并找到了解决方案。
显然,只能有一个默认排行榜(在我的问题代码中经过身份验证和设置)...这不需要像我原先想象的那样改变。 (我忘了它用于设置默认板)。
所以我需要做的是将排行榜标识符设置为第二个排行榜的标识符(这将是您在制作第二个排行榜时在iTunes Connect中使用的任何ID)。
我在报告这样的分数时在Game B View Controller中做到了:
-(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)authenticateLocalPlayer
,否则无需更改GameB bool
方法,在这种情况下,您可以将其添加到GameA Bool
下方:
if ([GKLocalPlayer localPlayer].authenticated) {
_gameCenterEnabled = YES; //added bool indentier to .h
_gameCenterEnabled2 = YES; //GameB bool
.
.
.
}
我希望这会有所帮助。