Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GameKit sending different score types

I have an app that has 5 different game modes, 3 of which have an integer score, and 2 of which have a time based score (how fast they complete the game).

How do I setup my reportScore: method so that my leaderboard that I setup in iTunes Connect (which displays high scores in a lowest to highest time format to the hundredth of a second) will receive my user's score in a time format?

I would like to send it as an NSTimeInterval.

The method that Apple Docs specifies accepts only an integer as a score:

- (void) reportScore: (int64_t) score forCategory: (NSString*) category
{
    GKScore *scoreReporter = [[GKScore alloc] initWithCategory:category];
    scoreReporter.value = score;

    [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
        if (error != nil)
        {
            //handle the score to submit again later
        }
    }];
}

UPDATE

I've done some research on this and I know that you can only send scores to Game Center leaderboards as an int64_t. So how do I format this integer so that my leaderboard will format it as a time to the hundredth of a second?

Thanks for your help!

like image 825
Liftoff Avatar asked Oct 26 '12 16:10

Liftoff


1 Answers

From Apple's documentation:

The value provided by a score object is interpreted by Game Center only when formatted for display. You determine how your scores are formatted when you define the leaderboard on iTunes Connect.

i.e., you need to convert the time to an integer and send that. If you want 1/100s precision, you could multiply the floating point NSTimeInterval by 100 and round that to an integer (e.g., 1.567s -> 157), then send that and select the leaderboard formatting accordingly (“Elapsed Time - To the hundredth of a second”, if I recall correctly).

like image 137
Arkku Avatar answered Nov 10 '22 23:11

Arkku