4

I implemented GKAchievement in a GKTurnBasedMatch and it was working initially. Now I am getting this error while reporting achievement for other player. Interestingly, same code awarding achievement to local Player

Terminating app due to uncaught exception 'GKInvalidArgumentException', reason: 'A GKAchievement can only be submitted for another player when ending a turn-based match.'

This is the code I am using for reporting GKAchievement

GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier:identifier forPlayer:playerID];
if(achievement) {
    achievement.percentComplete = percent;
    achievement.showsCompletionBanner = YES;
    [GKAchievement reportAchievements:@[achievement]
                   withCompletionHandler:^(NSError *error) {
        if(error) {
            NSLog(@"Unable to report achievement: %@", error);
        }
        completion(nil);
    }];
}

And this is the code for ending a GKTurnBasedMatch

 [self.gkMatch endMatchInTurnWithMatchData:archivedData
              completionHandler:^(NSError *error) {
    if(!error) {
        NSLog(@"Awarding Achievement to %@", [self getWinner].log);
        NSString *winnerPlayerId = [self getWinner].playerId;
            [self awardAchievement:@"someAchievement" to:winnerPlayerId  percentCompleted:100.0 completion:^(NSError *error1) {
                completion(error1);
            }];
    } else {
        NSLog(@"endMatchInTurnWithMatchData %@", error);
    }
}];

Help me in this.
Thanks.

Hassan Jawed
  • 1,650
  • 1
  • 12
  • 19

0 Answers0