iOS and OSX social leaderboards and highscore push notifications on top of Apple CloudKit
-
pod 'LeaderboardKit'
-
#import <LeaderboardKit/LeaderboardKit.h>
-
Setup leaderboards inside
application:didFinishLaunchingWithOptions:
:LKGameCenterIdentifierToNameTranform = ^NSString *(NSString *identifier){ return [identifier substringFromIndex:@"scores.".length]; }; LKGameCenterNameToIdentifierTranform = ^NSString *(NSString *name){ return [@"scores." stringByAppendingString:name]; }; [[LeaderboardKit shared] setupLeaderboardNames:@[@"3x3",@"4x4",@"5x5"]];
for leaderboard identifiers:
scores.3x3
,scores.4x4
andscores.5x5
[[LeaderboardKit shared] whenInitialized:^{
id<LKAccount> account = [[LeaderboardKit shared] accountWithClass:[LKGameCenter class]];
if (!account) {
account = [[LKGameCenter alloc] init];
[[LeaderboardKit shared] addAccount:account];
}
[account requestAuthWithViewController:self success:^{
[[[UIAlertView alloc] initWithTitle:@"Success" message:@"GameCenter account connected" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
} failure:^(NSError *error) {
[[[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}];
}];
- When need to configure some button state:
self.connectTwitterButton.enabled = NO;
[[LeaderboardKit shared] whenInitialized:^{
self.connectTwitterButton.enabled = ![[LeaderboardKit shared] accountForIdentifier:LKAccountIdentifierTwitter];
}];
- Connect ane social when player wants (Twitter, for example):
if ([LeaderboardKit shared].isInitialized && ![[LeaderboardKit shared] accountForIdentifier:LKAccountIdentifierTwitter])
{
id<LKAccount> account = [[LKTwitterAccount alloc] initWithUserRecord:[LeaderboardKit shared].userRecord];
[account requestAuthWithViewController:self success:^{
[[LeaderboardKit shared] setAccount:account forIdentifier:LKAccountIdentifierTwitter];
[[[UIAlertView alloc] initWithTitle:@"Success" message:@"Twitter account connected" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
} failure:^(NSError *error) {
[[[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}];
}
- Create fork
- Create new branch
- Add some commits to your branch
- Create Pull Request
- When pull request merged, delete brach