0

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

...
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
                    }
                }];
...

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

4

1 回答 1

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)];

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

于 2015-09-09T01:08:43.753 回答