如何在游戏中心获得朋友范围排名?

时间:2015-09-09 00:38:04

标签: objective-c game-center game-center-leaderboard

我在下面制作了这段代码,以便从游戏中心的朋友范围中获得排名。不幸的是,它只返回全球范围的排名。

...
GKLeaderboard *friendLeaderboard=[[GKLeaderboard alloc] initWithPlayers:@[[GKLocalPlayer localPlayer]]];
                [friendLeaderboard setIdentifier:LeaderboardID];
                [friendLeaderboard setTimeScope:GKLeaderboardTimeScopeAllTime];
                [friendLeaderboard setPlayerScope:GKLeaderboardPlayerScopeFriendsOnly];
                [friendLeaderboard setRange:NSMakeRange(1, 1)];
                [friendLeaderboard loadScoresWithCompletionHandler:^(NSArray *friendScores, NSError *error) {
                    if (error) {
                        completionHandler(NULL, NULL);
                        //[scoreReporter release];//auto release added
                    }
                    else{
                        GKScore* gScore = [globalLeaderboard localPlayerScore];
                        GKScore* fScore = [friendLeaderboard localPlayerScore];
                        NSLog(@"GCHelper globalScores: %@", gScore);
                        NSLog(@"GCHelper friendScores: %@", fScore); //NOT CORRECT
                        completionHandler(gScore, fScore);
                        //[scoreReporter release];//auto release added
                    }
                }];
...

除了循环完整的朋友排行榜之外,是否有正确或替代方式?

1 个答案:

答案 0 :(得分:0)

这是一个修复:

                //get friend rank
                GKLeaderboard *friendLeaderboard=[[GKLeaderboard alloc] init];//WithPlayers:@[[GKLocalPlayer localPlayer]]];// autorelease];
                [friendLeaderboard setIdentifier:LeaderboardID];
                [friendLeaderboard setTimeScope:GKLeaderboardTimeScopeAllTime];
                [friendLeaderboard setPlayerScope:GKLeaderboardPlayerScopeFriendsOnly];
                //[friendLeaderboard setRange:NSMakeRange(1, 1)];

一个奇怪的错误,但我想我需要牺牲一些效率