Cannot load top leaderboard score on iOS 7

落爺英雄遲暮 提交于 2019-12-24 04:23:06

问题


I had a function to load the top score from the leaderboard for my iOS game, and it worked in iOS 6 but it no longer works in iOS 7. The function I used is as follows:

- (void) retrieveGlobalHighScore {
if(userAuthenticated == true) {
    //NSLog(@"Attempting to retrieve global high score...");
    GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
    if (leaderboardRequest != nil) {
        leaderboardRequest.playerScope = GKLeaderboardPlayerScopeGlobal;
        leaderboardRequest.timeScope = GKLeaderboardTimeScopeAllTime;
        leaderboardRequest.range = NSMakeRange(1,1);
        [leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
            if (error != nil) {
                // handle the error. if (scores != nil)
                NSLog(@"ERROR: Issue loading global high score.");
                NSLog(@"Unresolved error %@", error);
            }
            if (scores != nil){
                // process the score information.
                globalHighScoreReturn = ((GKScore*)[scores objectAtIndex:0]).value;
            }
        }];
    }
} else {
    //NSLog(@"User is not authenticated. Global high score not loaded.");
  }
}

I now get the following error and cannot figure out how to fix it:

Error Domain=GKErrorDomain Code=17 
"The requested operations could not be completed because one or more parameters are invalid." 

UserInfo=0xf539250 {GKServerStatusCode=5053, NSUnderlyingError=0xf538670 "The operation couldn’t be completed. 

status = 5053, asking for legacy aggregate leaderboard on a game with no legacy aggregate leaderboard", NSLocalizedDescription=The requested operations could not be completed because one or more parameters are invalid.}

Any help would be greatly appreciated!


回答1:


This is what I had to add to fix the problem (iOS 7):

        leaderboardRequest.identifier = @"my_leaderboardID";



回答2:


I found the issue. In iOS 6, setting leaderboardRequest.category was not needed and the default leaderboard (I am only using 1) was automatically selected. In iOS 7, the category had to be specified. Specifying the identifier worked as well, however I am supporting both iOS 6 and 7.



来源:https://stackoverflow.com/questions/20432047/cannot-load-top-leaderboard-score-on-ios-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!