UPDATE:
Я создал свой собственный класс помощников, который работает со всеми видами приложений (также Cocos2D 1 и 2+)
https://github.com/alexblunck/ABGameKitHelper
Привет, я предлагаю вам использовать GKHelper Class от Steffen Itterheim! Я загрузил для вас GKHelper.h / GKHelper.m: http://www.cl.ly/7ReW
Затем следуйте этим инструкциям:
// 0.0 Добавить GameKit Framework в проект (спросите, если вы не знаете, как это сделать;))
// 0. Изменить "[window addSubview: viewController.view];" в AppDelegate.m, чтобы:
// Делаем это, если вы используете любой релиз cocos2D после 0.99.5:
window.rootViewController = viewController;
// 1. Добавьте Gamekithelper.h / .m в проект
// 2. Включить следующий делегат в данный заголовок:
<GameKitHelperProtocol>
// 3. Добавить методы делегата в .m
// 4. Добавьте GameKitHelper к «Scene»:
GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
gkHelper.delegate = self;
[gkHelper authenticateLocalPlayer];
// Добавление счета в таблицу лидеров:
GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper submitScore:scoreValue category:@"LeaderboardID"];
// Добавление завершения достижения:
GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper reportAchievementWithID:@"AchievementID" percentComplete:100];
Это методы делегата, которые необходимо добавить, упомянутые на шаге № 3:
#pragma mark GameKitHelper delegate methods
-(void) onLocalPlayerAuthenticationChanged
{
GKLocalPlayer* localPlayer = [GKLocalPlayer localPlayer];
CCLOG(@"LocalPlayer isAuthenticated changed to: %@", localPlayer.authenticated ? @"YES" : @"NO");
if (localPlayer.authenticated)
{
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper getLocalPlayerFriends];
//[gkHelper resetAchievements];
}
}
-(void) onFriendListReceived:(NSArray*)friends
{
CCLOG(@"onFriendListReceived: %@", [friends description]);
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper getPlayerInfo:friends];
}
-(void) onPlayerInfoReceived:(NSArray*)players
{
CCLOG(@"onPlayerInfoReceived: %@", [players description]);
}
-(void) onScoresSubmitted:(bool)success
{
CCLOG(@"onScoresSubmitted: %@", success ? @"YES" : @"NO");
}
-(void) onScoresReceived:(NSArray*)scores
{
CCLOG(@"onScoresReceived: %@", [scores description]);
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper showAchievements];
}
-(void) onAchievementReported:(GKAchievement*)achievement
{
CCLOG(@"onAchievementReported: %@", achievement);
}
-(void) onAchievementsLoaded:(NSDictionary*)achievements
{
CCLOG(@"onLocalPlayerAchievementsLoaded: %@", [achievements description]);
}
-(void) onResetAchievements:(bool)success
{
CCLOG(@"onResetAchievements: %@", success ? @"YES" : @"NO");
}
-(void) onLeaderboardViewDismissed
{
CCLOG(@"onLeaderboardViewDismissed");
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper retrieveTopTenAllTimeGlobalScores];
}
-(void) onAchievementsViewDismissed
{
CCLOG(@"onAchievementsViewDismissed");
}
-(void) onReceivedMatchmakingActivity:(NSInteger)activity
{
CCLOG(@"receivedMatchmakingActivity: %i", activity);
}
-(void) onMatchFound:(GKMatch*)match
{
CCLOG(@"onMatchFound: %@", match);
}
-(void) onPlayersAddedToMatch:(bool)success
{
CCLOG(@"onPlayersAddedToMatch: %@", success ? @"YES" : @"NO");
}
-(void) onMatchmakingViewDismissed
{
CCLOG(@"onMatchmakingViewDismissed");
}
-(void) onMatchmakingViewError
{
CCLOG(@"onMatchmakingViewError");
}
-(void) onPlayerConnected:(NSString*)playerID
{
CCLOG(@"onPlayerConnected: %@", playerID);
}
-(void) onPlayerDisconnected:(NSString*)playerID
{
CCLOG(@"onPlayerDisconnected: %@", playerID);
}
-(void) onStartMatch
{
CCLOG(@"onStartMatch");
}
-(void) onReceivedData:(NSData*)data fromPlayer:(NSString*)playerID
{
CCLOG(@"onReceivedData: %@ fromPlayer: %@", data, playerID);
}