Cannot load top leaderboard score on iOS 7 - ios

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!

This is what I had to add to fix the problem (iOS 7):
leaderboardRequest.identifier = #"my_leaderboardID";

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.

Related

NSURLErrorDomain code=-1005 from GKLeaderboard loadScoresWithCompletionHandler:

I am receiving the following error in a callback to loadScoresWithCompletionHandler:
Error Domain=NSURLErrorDomain Code=-1005
"The operation couldn’t be completed. (NSURLErrorDomain error -1005.)"
Other calls to Game Center both before and afterwards succeed. (They operate on various threads). If have initialized the leaderboard request as follows:
GKLeaderboard *leaderboard = [[GKLeaderboard alloc] init];
leaderboard.identifier = leaderboardIdentifier; // valid identifier
leaderboard.playerScope = GKLeaderboardPlayerScopeFriendsOnly;
leaderboard.range = NSMakeRange(1, 100); // max. allowed range.
leaderboard.timeScope = GKLeaderboardTimeScopeAllTime;
[leaderboard loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) {
// ...
}];
What is going on here and how can I overcome this problem?
The calls to loadScoresWithCompletionHandler: are made from an operation on an NSOperationQueue whose task it is to issue requests for scores (I am interested in each localPlayerScore) to several leaderboards and wait for all responses. The first response already carries the error.
UPDATE -1005 denotes kCFURLErrorNetworkConnectionLost; the underlying cause is still unclear.
UPDATE If I send only a single request (instead of as so far typically 6 in parallel) I receive error NSURLErrorDomain -1001, which denotes kCFURLErrorTimedOut, or GKErrorDomain 3 ...
For some reason this alternative call does not lead to errors:
GKLeaderboard *leaderboard =
[[GKLeaderboard alloc] initWithPlayers:#[ GKLocalPlayer.localPlayer ]];
leaderboard.identifier = leaderboardIdentifier;
leaderboard.timeScope = GKLeaderboardTimeScopeAllTime;
[leaderboard loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) {
// ...
}];
Problem solved.

IOS 7 game center

I am trying to use Game Center to achieve peer to peer communication. But I meet some issues while testing game center. The user authentication is fine, it went through. The problem is matchmaking.
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) {
if (error) {
NSLog(#"%#",error.localizedDescription);
}else if (match != nil) {
NSLog(#"good match");
[match setDelegate:self];
}else {
NSLog(#"other error");
}
}];
I want to create own request instead of using GKMatchmakerViewController. But the block code is NOT steady, some time it can work, some time gives me error: cannot connect to server, I don't know it's Game Center server's problem or my code?
Once the above code is working fine, then I set the following handler:
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
request.playersToInvite=[NSArray arrayWithObjects:#"G:****", nil];//yin
request.inviteMessage=#"Welcome to my Game";
request.inviteeResponseHandler=^(NSString *playerID, GKInviteeResponse response) {
if(response==0){
NSLog(#"Accepted....");
}else if(response==1){
NSLog(#"Declined....");
}else if(response==2){
NSLog(#"Failed....");
}else if(response==3){
NSLog(#"3");
}else if(response==4){
NSLog(#"4");
}else if(response==5){
NSLog(#"5");
}else{
NSLog(#"unknown...");
}
};
I tested on different iphone. Once one iphone sends request to other, other can receive the notification, but only other rejects the invitation, then sender iphone can receive, if other accepts, the sender iphone receive nothing. I don't know why this things happened????
And at the receiver iphone side the inviteHandler is working fine. This is wired I tested the whole day, I cannot make it through. I am very brand new with IOS developing. Please help me out of this, appreciate very much!!!!

Unable to fetch Leaderboard Scores in Game Center iOS 7

I'm trying to fetch the default leaderboard scores from Game Center (Sandbox mode) using the code provided in apple docs. It works fine on all iOS versions except iOS 7. I've added the identifier property as required for iOS 7 but it returns this error:
Error Domain=GKErrorDomain Code=17 "The requested operations could not be completed because one or more parameters are invalid." UserInfo=0x16c5cdf0 {GKServerStatusCode=5053, NSUnderlyingError=0x16cb68a0 "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.
The code I'm using to retrieve scores:
GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
if (leaderboardRequest != nil)
{
leaderboardRequest.playerScope = GKLeaderboardPlayerScopeGlobal;
leaderboardRequest.timeScope = GKLeaderboardTimeScopeAllTime;
leaderboardRequest.identifier = #"LEADERBOARD_NAME";
leaderboardRequest.range = NSMakeRange(1,100);
[leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
if (error != nil)
{
// Handle the error.
NSLog(#"%#",error.description);
}
if (scores != nil)
{
// Process the score information.
}
}];
}
Thanks in advance!

GameCenter not updating leaderboard

Using the sandboxed Gamecenter.
No matter what I do the scores never appear in a leaderboard.
I am using the following code:
- (void)scoreReported: (NSError*) error {
NSLog(#"%#",[error localizedDescription]);
}
- (void)submitScore{
if(self.currentScore > 0)
{
NSLog(#"Score: %lli submitted to leaderboard %#", self.currentScore, self.currentLeaderBoard);
[gameCenterManager reportScore: self.currentScore forCategory: self.currentLeaderBoard];
}
}
And scoreReported doesnt produce an error, yet the score doesnt appear in the leaderboard. I know the category is correct as I use currentLeaderBoard in:
- (void)showLeaderboard {
NSLog(#"leaderboard = %#", self.currentLeaderBoard);
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != NULL)
{
leaderboardController.category = self.currentLeaderBoard;
//leaderboardController.category = nil;
leaderboardController.timeScope = GKLeaderboardTimeScopeWeek;
leaderboardController.leaderboardDelegate = self;
[self presentModalViewController: leaderboardController animated: YES];
}
}
I have tried the usual
2 different sandbox GC accounts to get the leaderboard working
Even tried 4 different GC accounts each logging in on both the simulator (iOS 6.1) and device (iOS 6.0.1)
Yet still no joy
any suggestions - or is it just that the sandboxed gamecenter is far too buggy!!! (I would raise a bug about sandbox but the apple bug reporting form has a bug in it so that doesnt work either)
Score reporting to Game Center works almost immediately for me, even in sandbox mode.
Here are the few things you can try
Make sure the the Leaderboard identifiers are correct when reporting scores (Should exactly match with "Leaderboard ID"s in iTunesConnect)
Try Deleting the test data under "Manage Game Center" section of iTunesConnect
Delete the application, launch "Game Center" application in your device and goto "Games" tab and remove your app. Reinstall the app and try reporting the score again.
Make sure [gkScore reportScoreWithCompletionHandler:^(NSError *error) doesn't return any error
For those who want to know this what I changed my submitScore method to:
- (void)submitScore {
GKScore * GCscore = [[GKScore alloc] initWithCategory:self.currentLeaderBoard];
GCscore.value = [[NSUserDefaults standardUserDefaults] integerForKey:#"NEWSCORE"];
[GCscore reportScoreWithCompletionHandler:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^(void) {
if (error == NULL) {
NSLog(#"Score Sent");
} else {
NSLog(#"Score Failed, %#",[error localizedDescription]);
}
});
}];
}
and it worked

Odd Game Center behavior?

I'm trying to enable Game Center Leaderboard to my iPad game and I have learned that you need to post more than one score to a leaderboard for the scores to show in the default leaderboard UI.
I have two separete accounts that I used to post two different scores to the same leaderboard, but when I call loadScoresWithCompletionHandler I only get one score back (the score for the user I currently are logged in with).
Any ideas why?
GKLeaderboard *myLB = [[GKLeaderboard alloc] init];
myLB.category = #"MyLeaderboardId";
myLB.timeScope = GKLeaderboardTimeScopeAllTime;
myLB.playerScope = GKLeaderboardPlayerScopeGlobal;
myLB.range = NSMakeRange(1, 100);
[myLB loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) {
if (error != nil)
{
NSLog(#"%#", [error localizedDescription]);
}
if (scores != nil)
{
for (GKScore *score in scores)
{
NSLog(#"%lld", score.value);
}
}
}];
It works fine for me. Just add scores under another account.
I've got:
scores (
"<GKScore: 0x960e3e0><0x960e3e0> player=G:1208389607 rank=1 date=2012-01-19 12:56:47 +0000 value=27 formattedValue=27 context=(null)",
"<GKScore: 0x96a1bc0><0x96a1bc0> player=G:1176161436 rank=2 date=2012-01-19 08:35:06 +0000 value=16 formattedValue=16 context=(null)"
)
And center by standard controller show same results.
thanks,

Resources