-
Notifications
You must be signed in to change notification settings - Fork 0
Leaderboards
Sign in to http://pankia.com, enable the "Essential" feature, and create a leaderboard. When you finish creating, you get an "ID" assigned to the leaderboard. The ID is used to specify the target leaderboard in the following instruction.
To post a score to a leaderboard, call +[Pankia postScore:leaderboardId:isIncremental:]
.
- (void)postSomeScore {
// Post score value of 10 to the leaderboard with ID of 1
int64_t result = [Pankia postScore:10 leaderboardId:1 isIncremental:NO];
}
The new value will be returned. Note that it could be different from what you sent if the value is lower than the previous best.
Also note that, in case the user is offline or the connectivity with the server is flaky, it is possible that the score that is stored on the local device and the one that is stored on the server are different. It will be automatically resolved when the client is back online.
To get latest score on a leaderboard, use +[Pankia latestScoreOnLeaderboard:]
.
- (void)latestScoreOnLeaderboard10
{
NSLog(@"Latest score on leaderboard 10 is %lld", [Pankia latestScoreOnLeaderboard:10]);
}
You can also use these APIs for getting score in non-int score formats.
+[Pankia latestFloatScoreOnLeaderboard:]
+[Pankia latestFloatMoneyScoreOnLeaderboard:]
+[Pankia latestTimeScoreOnLeaderboard:]
+[Pankia latestMoneyScoreOnLeaderboard:]
The APIs above can use both the client is online and offline. Scores returned by these APIs are cached locally. If you want to fetch scores directly from the server, use +[Pankia fetchLatestLeaderboardsScore:onSuccess:onFailure:]
.
- (void)fetchLatestScoreOnLeaderboard10
{
[Pankia fetchLatestLeaderboardsScore:[NSArray arrayWithObject:[NSNumber numberWithInt:10]] onSuccess:^(NSArray *ranks) {
for (PNRank* rank in ranks) {
NSLog(@"Your current score on leaderboard %d is %lld" ,rank.leaderboardId, rank.score);
}
} onFailure:^(NSError *error) {
NSLog(@"Failure %@", error);
}];
}
To fetch a user rank, call fetchRankOnLeaderboard
. The type of the score is long long int. Be careful when you use it with NSLog or snprintf.
- (void)fetchRankOnLeaderboard26
{
// Fetch the user rank on leaderbaord 26
[Pankia fetchRankOnLeaderboard:26 onSuccess:^(PNRank* rank){
NSLog(@"Your current score on leaderboard %d is %lld" ,rank.leaderboardId, rank.score);
} onFailure:^(NSError* error){
NSLog(@"Error. %@", error);
}];
}