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!
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With