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
-
delegate
Set your delegate that should receive the KKGameKitHelperProtocol messages.
property -
isGameCenterAvailable
Check this to see if Game Center is supported on the current Device. See: http://support.apple.com/kb/HT4314
property -
lastError
If 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 -
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 -
currentMatch
The current match object. May be nil if there’s no match.
property -
matchStarted
Indicates whether the current match has already started.
property -
+ sharedGameKitHelper
returns the singleton object, like this: [KKGameKitHelper sharedGameKitHelper]
-
– authenticateLocalPlayer
try to authenticate the local player
-
– getLocalPlayerFriends
request 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
-
– retrieveTopTenAllTimeGlobalScores
convenience 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).
-
– resetAchievements
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.
-
– reportCachedAchievements
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.
-
– saveCachedAchievements
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.
-
– loadAchievements
Starts obtaining the local player’s achievements from Game Center.
-
– disconnectCurrentMatch
Disconnect 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.
-
– cancelMatchmakingRequest
Cancels any matchmaking request currently in progress.
-
– queryMatchmakingActivity
Request 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)
-
– showLeaderboard
Brings up the Game Center Leaderboard view.
-
– showAchievements
Brings 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 *achievements
Declared In
KKGameKitHelper.h
currentMatch
The current match object. May be nil if there’s no match.
@property (nonatomic, retain) GKMatch *currentMatch
Declared In
KKGameKitHelper.h
delegate
Set your delegate that should receive the KKGameKitHelperProtocol messages.
@property (nonatomic, assign) id<KKGameKitHelperProtocol> delegate
Declared In
KKGameKitHelper.h
isGameCenterAvailable
Check this to see if Game Center is supported on the current Device. See: http://support.apple.com/kb/HT4314
@property (nonatomic, readonly) BOOL isGameCenterAvailable
Declared In
KKGameKitHelper.h
Instance Methods
addPlayersToMatch:
Request to add players to a match.
- (void)addPlayersToMatch:(GKMatchRequest *)request
Declared In
KKGameKitHelper.h
authenticateLocalPlayer
try to authenticate the local player
- (void)authenticateLocalPlayer
Declared In
KKGameKitHelper.h
cancelMatchmakingRequest
Cancels any matchmaking request currently in progress.
- (void)cancelMatchmakingRequest
Declared In
KKGameKitHelper.h
disconnectCurrentMatch
Disconnect from the current match
- (void)disconnectCurrentMatch
Declared In
KKGameKitHelper.h
findMatchForRequest:
Request a match for the given request.
- (void)findMatchForRequest:(GKMatchRequest *)request
Declared In
KKGameKitHelper.h
getAchievementByID:
returns a cached achievement by its identifier
- (GKAchievement *)getAchievementByID:(NSString *)identifier
Declared In
KKGameKitHelper.h
getLocalPlayerFriends
request the local player’s friends
- (void)getLocalPlayerFriends
Declared In
KKGameKitHelper.h
getPlayerInfo:
requests info about a set of players
- (void)getPlayerInfo:(NSArray *)players
Declared In
KKGameKitHelper.h
loadAchievements
Starts obtaining the local player’s achievements from Game Center.
- (void)loadAchievements
Declared In
KKGameKitHelper.h
queryMatchmakingActivity
Request the matchmaking activity to get an indicator on how many games are played.
- (void)queryMatchmakingActivity
Declared In
KKGameKitHelper.h
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).
- (void)reportAchievementWithID:(NSString *)identifier percentComplete:(float)percent
Declared In
KKGameKitHelper.h
reportCachedAchievements
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)reportCachedAchievements
Declared In
KKGameKitHelper.h
resetAchievements
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)resetAchievements
Declared In
KKGameKitHelper.h
retrieveScoresForPlayers: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)timeScope
Declared In
KKGameKitHelper.h
retrieveTopTenAllTimeGlobalScores
convenience method, requests the Top 10 all time global highscores
- (void)retrieveTopTenAllTimeGlobalScores
Declared In
KKGameKitHelper.h
saveCachedAchievements
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)saveCachedAchievements
Declared In
KKGameKitHelper.h
sendDataToAllPlayers:
sends the given NSData to all players (unreliably)
- (void)sendDataToAllPlayers:(NSData *)data
Declared In
KKGameKitHelper.h
sendDataToAllPlayers:length:
sends the given pointer with the given length to all players (unreliably)
- (void)sendDataToAllPlayers:(void *)data length:(NSUInteger)length
Declared In
KKGameKitHelper.h
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)
- (void)sendDataToAllPlayers:(void *)data length:(NSUInteger)length reliable:(BOOL)reliable
Declared In
KKGameKitHelper.h
sendDataToAllPlayers: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)reliable
Declared In
KKGameKitHelper.h
setupMatchInvitationHandlerWithMinPlayers:maxPlayers:
creates the handler for processing match invitations from other players
- (void)setupMatchInvitationHandlerWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers
Declared In
KKGameKitHelper.h
showAchievements
Brings up the Game Center Achievements view.
- (void)showAchievements
Declared In
KKGameKitHelper.h
showLeaderboard
Brings up the Game Center Leaderboard view.
- (void)showLeaderboard
Declared In
KKGameKitHelper.h
showMatchmakerWithInvite:
Brings up the Game Center Matchmaking view after receiving an invite.
- (void)showMatchmakerWithInvite:(GKInvite *)invite
Declared In
KKGameKitHelper.h