KKGameKitHelper Class Reference
| Inherits from | NSObject |
| Conforms to | GKAchievementViewControllerDelegate GKLeaderboardViewControllerDelegate GKMatchDelegate GKMatchmakerViewControllerDelegate |
| Declared in | KKGameKitHelper.h |
Overview
Singleton that wraps a lot of common Game Kit and Game Center functionality and forwards events to a delegate implementing the GameKitHelperProtocol. It ensures that certain functions are only called if Game Center is available on the current device and the local player is authenticated. It also caches achievements so that they don’t get lost if the connection is interrupted.
Tasks
-
delegateSet your delegate that should receive the KKGameKitHelperProtocol messages.
property -
isGameCenterAvailableCheck this to see if Game Center is supported on the current Device. See: http://support.apple.com/kb/HT4314
property -
lastErrorIf your delegate receives an error message, you can check this property for the actual NSError object. This allows you to print out the cause of the error to console log or display an Alert view.
property -
achievementsThe cached achievements of the local player. GameKitHelper will save the achievements between sessions to ensure that achievements are updated on Game Center on next app start even if connection was lost.
property -
currentMatchThe current match object. May be nil if there’s no match.
property -
matchStartedIndicates whether the current match has already started.
property -
+ sharedGameKitHelperreturns the singleton object, like this: [KKGameKitHelper sharedGameKitHelper]
-
– authenticateLocalPlayertry to authenticate the local player
-
– getLocalPlayerFriendsrequest the local player’s friends
-
– getPlayerInfo:requests info about a set of players
-
– submitScore:category:submit a score to Game Center
-
– retrieveScoresForPlayers:category:range:playerScope:timeScope:request the scores of a set of players, in a given category, range and scopes
-
– retrieveTopTenAllTimeGlobalScoresconvenience method, requests the Top 10 all time global highscores
-
– getAchievementByID:returns a cached achievement by its identifier
-
– reportAchievementWithID:percentComplete:Send an achievement update to Game Center. The message will only be sent if completion percent is greater than any percent previously submitted (Game Center does not allow achievements to regress and would simply ignore such a message).
-
– resetAchievementsResets all achievement progress. Be very careful with this, should only be run after the player has understood the consequences. You’ll use it rather often during development however. It will also clean all cached achievements.
-
– reportCachedAchievementsTry to send any cached Achievements to Game Center. If updating an achievement fails for any reason, the achievement is cached. By default, GameKitHelper will call this method when the local player is authenticated, so that any previously gained achievements are hopefully sent the next time the player runs the App.
-
– saveCachedAchievementsSaves all cached achievements to persist them between sessions. By default every time an achievement is cached the cached achievements are saved to disk, so they also persist even when the App crashes.
-
– loadAchievementsStarts obtaining the local player’s achievements from Game Center.
-
– disconnectCurrentMatchDisconnect from the current match
-
– setupMatchInvitationHandlerWithMinPlayers:maxPlayers:creates the handler for processing match invitations from other players
-
– findMatchForRequest:Request a match for the given request.
-
– addPlayersToMatch:Request to add players to a match.
-
– cancelMatchmakingRequestCancels any matchmaking request currently in progress.
-
– queryMatchmakingActivityRequest the matchmaking activity to get an indicator on how many games are played.
-
– sendDataToAllPlayers:sends the given NSData to all players (unreliably)
-
– sendDataToAllPlayers:reliable:sends the given NSData to all players either reliably (safe but slow) or unreliably (arrival not guaranteed, but fast)
-
– sendDataToAllPlayers:length:sends the given pointer with the given length to all players (unreliably)
-
– sendDataToAllPlayers:length:reliable:sends the given pointer with the given length to all players either reliably (safe but slow) or unreliably (arrival not guaranteed, but fast)
-
– showLeaderboardBrings up the Game Center Leaderboard view.
-
– showAchievementsBrings up the Game Center Achievements view.
-
– showMatchmakerWithInvite:Brings up the Game Center Matchmaking view after receiving an invite.
-
– showMatchmakerWithRequest:Brings up the Game Center Matchmaking view with a match request.
Properties
achievements
The cached achievements of the local player. GameKitHelper will save the achievements between sessions to ensure that achievements are updated on Game Center on next app start even if connection was lost.
@property (nonatomic, readonly) NSMutableDictionary *achievementsDeclared In
KKGameKitHelper.hcurrentMatch
The current match object. May be nil if there’s no match.
@property (nonatomic, retain) GKMatch *currentMatchDeclared In
KKGameKitHelper.hdelegate
Set your delegate that should receive the KKGameKitHelperProtocol messages.
@property (nonatomic, assign) id<KKGameKitHelperProtocol> delegateDeclared In
KKGameKitHelper.hisGameCenterAvailable
Check this to see if Game Center is supported on the current Device. See: http://support.apple.com/kb/HT4314
@property (nonatomic, readonly) BOOL isGameCenterAvailableDeclared In
KKGameKitHelper.hInstance Methods
addPlayersToMatch:
Request to add players to a match.
- (void)addPlayersToMatch:(GKMatchRequest *)requestDeclared In
KKGameKitHelper.hauthenticateLocalPlayer
try to authenticate the local player
- (void)authenticateLocalPlayerDeclared In
KKGameKitHelper.hcancelMatchmakingRequest
Cancels any matchmaking request currently in progress.
- (void)cancelMatchmakingRequestDeclared In
KKGameKitHelper.hdisconnectCurrentMatch
Disconnect from the current match
- (void)disconnectCurrentMatchDeclared In
KKGameKitHelper.hfindMatchForRequest:
Request a match for the given request.
- (void)findMatchForRequest:(GKMatchRequest *)requestDeclared In
KKGameKitHelper.hgetAchievementByID:
returns a cached achievement by its identifier
- (GKAchievement *)getAchievementByID:(NSString *)identifierDeclared In
KKGameKitHelper.hgetLocalPlayerFriends
request the local player’s friends
- (void)getLocalPlayerFriendsDeclared In
KKGameKitHelper.hgetPlayerInfo:
requests info about a set of players
- (void)getPlayerInfo:(NSArray *)playersDeclared In
KKGameKitHelper.hloadAchievements
Starts obtaining the local player’s achievements from Game Center.
- (void)loadAchievementsDeclared In
KKGameKitHelper.hqueryMatchmakingActivity
Request the matchmaking activity to get an indicator on how many games are played.
- (void)queryMatchmakingActivityDeclared In
KKGameKitHelper.hreportAchievementWithID:percentComplete:
Send an achievement update to Game Center. The message will only be sent if completion percent is greater than any percent previously submitted (Game Center does not allow achievements to regress and would simply ignore such a message).
- (void)reportAchievementWithID:(NSString *)identifier percentComplete:(float)percentDeclared In
KKGameKitHelper.hreportCachedAchievements
Try to send any cached Achievements to Game Center. If updating an achievement fails for any reason, the achievement is cached. By default, GameKitHelper will call this method when the local player is authenticated, so that any previously gained achievements are hopefully sent the next time the player runs the App.
- (void)reportCachedAchievementsDeclared In
KKGameKitHelper.hresetAchievements
Resets all achievement progress. Be very careful with this, should only be run after the player has understood the consequences. You’ll use it rather often during development however. It will also clean all cached achievements.
- (void)resetAchievementsDeclared In
KKGameKitHelper.hretrieveScoresForPlayers:category:range:playerScope:timeScope:
request the scores of a set of players, in a given category, range and scopes
- (void)retrieveScoresForPlayers:(NSArray *)players category:(NSString *)category range:(NSRange)range playerScope:(GKLeaderboardPlayerScope)playerScope timeScope:(GKLeaderboardTimeScope)timeScopeDeclared In
KKGameKitHelper.hretrieveTopTenAllTimeGlobalScores
convenience method, requests the Top 10 all time global highscores
- (void)retrieveTopTenAllTimeGlobalScoresDeclared In
KKGameKitHelper.hsaveCachedAchievements
Saves all cached achievements to persist them between sessions. By default every time an achievement is cached the cached achievements are saved to disk, so they also persist even when the App crashes.
- (void)saveCachedAchievementsDeclared In
KKGameKitHelper.hsendDataToAllPlayers:
sends the given NSData to all players (unreliably)
- (void)sendDataToAllPlayers:(NSData *)dataDeclared In
KKGameKitHelper.hsendDataToAllPlayers:length:
sends the given pointer with the given length to all players (unreliably)
- (void)sendDataToAllPlayers:(void *)data length:(NSUInteger)lengthDeclared In
KKGameKitHelper.hsendDataToAllPlayers:length:reliable:
sends the given pointer with the given length to all players either reliably (safe but slow) or unreliably (arrival not guaranteed, but fast)
- (void)sendDataToAllPlayers:(void *)data length:(NSUInteger)length reliable:(BOOL)reliableDeclared In
KKGameKitHelper.hsendDataToAllPlayers:reliable:
sends the given NSData to all players either reliably (safe but slow) or unreliably (arrival not guaranteed, but fast)
- (void)sendDataToAllPlayers:(NSData *)data reliable:(BOOL)reliableDeclared In
KKGameKitHelper.hsetupMatchInvitationHandlerWithMinPlayers:maxPlayers:
creates the handler for processing match invitations from other players
- (void)setupMatchInvitationHandlerWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayersDeclared In
KKGameKitHelper.hshowAchievements
Brings up the Game Center Achievements view.
- (void)showAchievementsDeclared In
KKGameKitHelper.hshowLeaderboard
Brings up the Game Center Leaderboard view.
- (void)showLeaderboardDeclared In
KKGameKitHelper.hshowMatchmakerWithInvite:
Brings up the Game Center Matchmaking view after receiving an invite.
- (void)showMatchmakerWithInvite:(GKInvite *)inviteDeclared In
KKGameKitHelper.h