Chris
Chris

Reputation: 27394

Game Center crash in iOS6

My game has been working perfectly fine in iOS5 for a year. After updating it to work with iOS6 it now crashes when attempting to send scores in Game Center. It crashes on the reportScoreWithCompletionHandler line in the code

- (void)sendScore:(GKScore *)score {
    [score reportScoreWithCompletionHandler:^(NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^(void)
                       {
                           if (error == NULL) {
                               NSLog(@"Successfully sent score!");
                               [scoresToReport removeObject:score];                
                           } else {
                               NSLog(@"Score failed to send... will try again later.  Reason: %@", error.localizedDescription);                
                           }
                       });
    }];
}

What am I doing wrong here?

Update

Having looked about a bit it seems there may also be an issue with authenticateWithCompletionHandler... My code for that is below.. If this is to blame how can I update it so it works?

- (void)authenticateLocalUser { 

    if (!gameCenterAvailable) return;

    NSLog(@"Authenticating local user...");
    if ([GKLocalPlayer localPlayer].authenticated == NO) {     
        [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:nil];        
    } else {
        NSLog(@"Already authenticated!");
    }
}

Upvotes: 0

Views: 313

Answers (1)

Chris
Chris

Reputation: 27394

I found the solution here

It seems you have to create a copy of the score and submit the copy. It only seems to happen when resending a saved score. This may be because it tries to prevent you sending a GKScore from a leaderboard?

// Pull the score value and category from the passed in score
int scoreValue = score.value;
NSString*scoreCategory = score.category;

// Create a new temporary score with these values
GKScore *toReport = [[[GKScore alloc]
initWithCategory:scoreCategory] autorelease];
toReport.value = scoreValue;

Upvotes: 1

Related Questions