-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
iRare Media
committed
Nov 28, 2013
1 parent
e76c965
commit 6a3ad10
Showing
9 changed files
with
1,869 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
// | ||
// GameCenterManager.h | ||
// | ||
// Created by Nihal Ahmed on 12-03-16. Updated by iRare Media on 7/2/13. | ||
// Copyright (c) 2012 NABZ Software. All rights reserved. | ||
// | ||
|
||
#warning Definition of GameCenterManagerKey is required. Change this value to your own secret key. | ||
#define kGameCenterManagerKey [@"MyKey" dataUsingEncoding:NSUTF8StringEncoding] | ||
|
||
#define LIBRARY_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Library"] | ||
#define kGameCenterManagerDataFile @"GameCenterManager.plist" | ||
#define kGameCenterManagerDataPath [LIBRARY_FOLDER stringByAppendingPathComponent:kGameCenterManagerDataFile] | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <GameKit/GameKit.h> | ||
#import "Reachability.h" | ||
#import "NSDataAES256.h" | ||
|
||
/// Leaderboard sort order. Use this value when submitting new leaderboard scores. This value should match the value set in iTunes Connect for the speicifed leaderboard. | ||
typedef enum GameCenterSortOrder { | ||
/// Scores are sorted highest to lowest. Higher scores are on the top of the leaderboard | ||
GameCenterSortOrderHighToLow, | ||
/// Scores are sorted lowest to highest. Lower scores are on the top of the leaderboard | ||
GameCenterSortOrderLowToHigh | ||
} GameCenterSortOrder; | ||
|
||
enum { | ||
/// An unknown error occurred | ||
GCMErrorUnknown = 1, | ||
/// GameCenterManager is unavailable, possibly for a variety of reasons | ||
GCMErrorNotAvailable = 2, | ||
/// The requested feature is unavailable on the current device or iOS version | ||
GCMErrorFeatureNotAvailable = 3, | ||
/// There is no active internet connection for the requested operation | ||
GCMErrorInternetNotAvailable = 4, | ||
/// The achievement data submitted was not valid because there were missing parameters | ||
GCMErrorAchievementDataMissing = 5 | ||
}; | ||
/// GameCenterManager error codes that may be passed in a completion handler's error parameter | ||
typedef NSInteger GCMErrorCode; | ||
|
||
/// GameCenter Manager helps to manage Game Center in iOS and Mac apps. Report and keep track of high scores, achievements, and challenges for different players. GameCenter Manager also takes care of the heavy lifting - checking internet availability, saving data when offline and uploading it when online, etc. | ||
@class GameCenterManager; | ||
@protocol GameCenterManagerDelegate; | ||
@interface GameCenterManager : NSObject { | ||
NSMutableArray *GCMLeaderboards; | ||
#if TARGET_OS_IPHONE | ||
UIBackgroundTaskIdentifier backgroundProcess; | ||
#endif | ||
} | ||
|
||
/// GameCenterManager delegate property that can be used to set the delegate | ||
@property (nonatomic, weak) id <GameCenterManagerDelegate> delegate; | ||
|
||
/// Returns the shared instance of GameCenterManager. | ||
+ (GameCenterManager *)sharedManager; | ||
|
||
|
||
|
||
/// Initializes Game Center Manager. Should be called at app launch. | ||
- (void)initGameCenter; | ||
|
||
/// Synchronizes local player data with Game Center data. | ||
- (void)syncGameCenter; | ||
|
||
|
||
|
||
/** Saves score locally and reports it to Game Center. If error occurs, score is saved to be submitted later. | ||
@param score The int value of the score to be submitted to Game Center. This score should not be formatted, instead it should be a plain int. For example, if you wanted to submit a score of 45.28 meters then you would submit it as an integer of 4528. To format your scores, you must set the Score Formatter for your leaderboard in iTunes Connect. | ||
@param identifier The Leaderboard ID set through iTunes Connect. This is different from the name of the leaderboard, and it is not shown to the user. | ||
@param order The score sort order that you set in iTunes Connect - either high to low or low to high. This is used to determine if the user has a new highscore before submitting. */ | ||
- (void)saveAndReportScore:(int)score leaderboard:(NSString *)identifier sortOrder:(GameCenterSortOrder)order __attribute__((nonnull)); | ||
|
||
/** Saves achievement locally and reports it to Game Center. If error occurs, achievement is saved to be submitted later. | ||
@param identifier The Achievement ID set through iTunes Connect. This is different from the name of the achievement, and it is not shown to the user. | ||
@param percentComplete A percentage value that states how far the player has progressed on this achievement. The range of legal values is between 0.0 and 100.0. Submitting 100.0 will mark the achievement as completed. Submitting a percent which is lower than what the user has already achieved will be ignored - the user's achievement progress cannot go down. | ||
@param displayNotification YES if GCManager should display a Game Center Achievement banner. NO if no banner should be displayed */ | ||
- (void)saveAndReportAchievement:(NSString *)identifier percentComplete:(double)percentComplete shouldDisplayNotification:(BOOL)displayNotification __attribute__((nonnull)); | ||
|
||
|
||
|
||
/// Reports scores and achievements which could not be reported earlier. | ||
- (void)reportSavedScoresAndAchievements; | ||
|
||
/// Saves score to be submitted later. | ||
- (void)saveScoreToReportLater:(GKScore *)score; | ||
|
||
/// Saves achievement to be submitted later. | ||
- (void)saveAchievementToReportLater:(NSString *)identifier percentComplete:(double)percentComplete; | ||
|
||
|
||
|
||
/// Returns local player's high score for specified leaderboard. | ||
- (int)highScoreForLeaderboard:(NSString *)identifier; | ||
|
||
/// Returns local player's high scores for multiple leaderboards. | ||
- (NSDictionary *)highScoreForLeaderboards:(NSArray *)identifiers; | ||
|
||
|
||
|
||
/// Returns local player's percent completed for specified achievement. | ||
- (double)progressForAchievement:(NSString *)identifier; | ||
|
||
/// Returns local player's percent completed for multiple achievements. | ||
- (NSDictionary *)progressForAchievements:(NSArray *)identifiers; | ||
|
||
|
||
|
||
/** Gets a list of challenges for the current player and game. If GameCenter is not available it will return nil and provide an error using the gameCenterManager:error: delegate method. Use the completion handler to get challenges. | ||
@param handler Completion handler with an NSArray containing challenges and an NSError. The NSError object will be nil if there is no error. */ | ||
- (void)getChallengesWithCompletion:(void (^)(NSArray *challenges, NSError *error))handler __attribute__((nonnull)); | ||
|
||
|
||
#if TARGET_OS_IPHONE | ||
/// Resets all of the local player's achievements and progress for the current game | ||
- (void)resetAchievementsWithCompletion:(void (^)(NSError *error))handler __attribute__((nonnull)); | ||
#else | ||
/// Resets all of the local player's achievements and progress for the current game | ||
- (void)resetAchievementsWithCompletion:(void (^)(NSError *error))handler __attribute__((nonnull)); | ||
|
||
/// DEPRECATED. Use resetAchievementsWithCompletion: instead | ||
- (void)resetAchievements __deprecated __unavailable; | ||
#endif | ||
|
||
|
||
/// Returns currently authenticated local player ID. If no player is authenticated, "unknownPlayer" is returned. | ||
- (NSString *)localPlayerId; | ||
|
||
/// Returns currently authenticated local player's display name (alias or actual name depending on friendship). If no player is authenticated, "unknownPlayer" is returned. Player Alias will be returned if the Display Name property is not available | ||
- (NSString *)localPlayerDisplayName; | ||
|
||
/// Returns currently authenticated local player and all associated data. If no player is authenticated, `nil` is returned. | ||
- (GKLocalPlayer *)localPlayerData; | ||
|
||
#if TARGET_OS_IPHONE | ||
/// Fetches a UIImage with the local player's profile picture at full resolution. The completion handler passes a UIImage object when the image is downloaded from the GameCenter Servers | ||
- (void)localPlayerPhoto:(void (^)(UIImage *playerPhoto))handler __attribute__((nonnull)) __OSX_AVAILABLE_STARTING(__OSX_10_8,__IPHONE_5_0); | ||
#else | ||
/// Fetches an NSImage with the local player's profile picture at full resolution. The completion handler passes an NSImage object when the image is downloaded from the GameCenter Servers | ||
- (void)localPlayerPhoto:(void (^)(NSImage *playerPhoto))handler __attribute__((nonnull)); | ||
#endif | ||
|
||
|
||
|
||
/// Returns YES if an active internet connection is available. | ||
- (BOOL)isInternetAvailable; | ||
|
||
/// Check if GameCenter is supported | ||
- (BOOL)checkGameCenterAvailability; | ||
|
||
/// Use this property to check if Game Center is available and supported on the current device. | ||
@property (nonatomic, assign) BOOL isGameCenterAvailable; | ||
|
||
|
||
@end | ||
|
||
|
||
/// GameCenterManager Delegate. Used for deeper control of the GameCenterManager class - allows for notification subscription, error reporting, and availability handling. | ||
@protocol GameCenterManagerDelegate <NSObject> | ||
|
||
#if TARGET_OS_IPHONE | ||
@required | ||
/// Required Delegate Method called when the user needs to be authenticated using the GameCenter Login View Controller | ||
- (void)gameCenterManager:(GameCenterManager *)manager authenticateUser:(UIViewController *)gameCenterLoginController; | ||
#endif | ||
|
||
@optional | ||
/// Delegate Method called when the availability of GameCenter changes | ||
- (void)gameCenterManager:(GameCenterManager *)manager availabilityChanged:(NSDictionary *)availabilityInformation; | ||
|
||
/// Delegate Method called when the there is an error with GameCenter or GC Manager | ||
- (void)gameCenterManager:(GameCenterManager *)manager error:(NSError *)error; | ||
|
||
/// Sent to the delegate when a score is reported to GameCenter | ||
- (void)gameCenterManager:(GameCenterManager *)manager reportedScore:(GKScore *)score withError:(NSError *)error; | ||
/// Sent to the delegate when an achievement is reported to GameCenter | ||
- (void)gameCenterManager:(GameCenterManager *)manager reportedAchievement:(GKAchievement *)achievement withError:(NSError *)error; | ||
|
||
/// Sent to the delegate when an achievement is saved locally | ||
- (void)gameCenterManager:(GameCenterManager *)manager didSaveAchievement:(GKAchievement *)achievement; | ||
/// Sent to the delegate when a score is saved locally | ||
- (void)gameCenterManager:(GameCenterManager *)manager didSaveScore:(GKScore *)score; | ||
|
||
|
||
- (void)gameCenterManager:(GameCenterManager *)manager savedScore:(GKScore *)score __deprecated; | ||
- (void)gameCenterManager:(GameCenterManager *)manager savedAchievement:(NSDictionary *)achievementInformation __deprecated; | ||
- (void)gameCenterManager:(GameCenterManager *)manager reportedScore:(NSDictionary *)scoreInformation __deprecated; | ||
- (void)gameCenterManager:(GameCenterManager *)manager reportedAchievement:(NSDictionary *)achievementInformation __deprecated; | ||
- (void)gameCenterManager:(GameCenterManager *)manager resetAchievements:(NSError *)error __deprecated __unavailable; | ||
|
||
@end | ||
|
||
|
Oops, something went wrong.