Skip to content

Commit

Permalink
Fixed issue where new GKLeaderboard object's category property was be…
Browse files Browse the repository at this point in the history
…ing set to the saved GKLeaderboard object.

Fixing this seemed to cause the object to be removed from the
_leaderboards ivar, so I had to add the check to prevent an
NSRangeException. Please feel free to clean up my solution if you can
discover why this is occurring.
  • Loading branch information
michael-patzer committed Jul 2, 2013
1 parent 667b64c commit de34043
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions GameCenterManager/GC Manager/GameCenterManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ - (void)syncGameCenter {

if (_leaderboards.count > 0) {
GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] initWithPlayerIDs:[NSArray arrayWithObject:[[GameCenterManager sharedManager] localPlayerId]]];
[leaderboardRequest setCategory:[_leaderboards objectAtIndex:0]];
[leaderboardRequest setCategory:[(GKLeaderboard *)[_leaderboards objectAtIndex:0] category]];
[leaderboardRequest loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) {
if (error == nil) {
if (scores.count > 0) {
Expand All @@ -211,7 +211,12 @@ - (void)syncGameCenter {
[saveData writeToFile:kGameCenterManagerDataPath atomically:YES];
}

[_leaderboards removeObjectAtIndex:0];
// Seeing an NSRangeException for an empty arrat when trying to remove the object
// Despite the check above in this scope that leaderboards count is > 0
if (_leaderboards.count > 0) {
[_leaderboards removeObjectAtIndex:0];
}

[[GameCenterManager sharedManager] syncGameCenter];
} else {
NSDictionary *errorDictionary = [NSDictionary dictionaryWithObject:error forKey:@"error"];
Expand All @@ -221,7 +226,8 @@ - (void)syncGameCenter {
});
}
}];
} else {
}
else {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:[@"scoresSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]];
[[GameCenterManager sharedManager] syncGameCenter];
}
Expand Down

0 comments on commit de34043

Please sign in to comment.