Search code examples
iphoneobjective-cipodgame-center

Informing the user that a score was submitted to Game Center


Is there any method to tell the user that his score submitted successfully or just use an alert view.

I mean something like the Game Center welcome message: "Welcome Back, user"


Solution

  • Game Center score submission implements a block callback which you can use to handle errors or successful submission. This is a function copied directly from the developer documentation:

    - (void) reportScore: (int64_t) score forCategory: (NSString*) category{
      GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];
      scoreReporter.value = score;
    
      [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
        if (error != nil){
          //There was an error submitting the score.
        }else {
          //The score was successfully submitted.
        }
      }];
    }
    

    In terms of the user interface, like the sliding "welcome back" view, you'll have to make your own user interface for that. (I just use UIAlertview, but that's totally up to you.)