'unable to update gamecenter high score

I am trying to update game center leaderboard high score.

I am using the following code:

- (void) reportScore: (int64_t) score forLeaderboardID: (NSString*) identifier
{
    if([GKLocalPlayer localPlayer].authenticated == YES)
    {
        NSLog(@"%@",[[GKLocalPlayer localPlayer] playerID]);
        NSString *pId=[[GKLocalPlayer localPlayer] playerID];
        NSString* PlayerId = [NSString stringWithFormat: @"%@",pId];
        
        NSString *alias = [GKLocalPlayer localPlayer].alias;
        NSString *name = [GKLocalPlayer localPlayer].displayName;
        
        
        NSLog(@"%@",PlayerId);
        NSLog(@"%@",alias);
        NSLog(@"%@",name);
        
        NSArray *playerArray=[NSArray arrayWithObject: PlayerId];
        NSLog(@"%@",[playerArray objectAtIndex:0]);
        NSString *String = [[NSString stringWithString:[playerArray objectAtIndex:0]] stringByReplacingOccurrencesOfString:@"G:" withString:@""];
        GKPlayer* player= NULL;
        GKScore *scoreReporter = [[GKScore alloc] initWithLeaderboardIdentifier: identifier];
        
        
//        GKScore *scoreReporter = [[GKScore alloc] initWithLeaderboardIdentifier:identifier player:String];
        scoreReporter.value = score;
        
        //    scoreReporter.context = 0;
        
        NSArray *scores = @[scoreReporter];
        [GKScore reportScores:scores withCompletionHandler:^(NSError *error) {
            //Do something interesting here.
            [[[[UIAlertView alloc] initWithTitle: @"GameCenter" message: @"Score Submitted Successfully" delegate: NULL cancelButtonTitle: @"OK" otherButtonTitles: NULL] autorelease] show];
        }];
        
    }
}

I am able to post score first time after creating a leaderboard on itunes but only first time after submitting score I can't update my own score.

I researched that I need to use player Id, without player Id I can't update player Score.

I am using above code that works 1st time. How to update score of a player?



Solution 1:[1]

It may be working this code. You should try call function by NSNotificationCenter.

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(reportScore:)
                                             name:@"ReportScore"
                                           object:nil];

-(void)reportScore:(NSNotification *)notification;

I hope help you this code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ErimKurt