diff --git a/AppArtworkIcon@2x.png b/AppArtworkIcon@2x.png deleted file mode 100755 index 2acc880..0000000 Binary files a/AppArtworkIcon@2x.png and /dev/null differ diff --git a/GameCenterManager Mac/AppDelegateMac.h b/GameCenterManager Mac/AppDelegateMac.h index 38d6cbd..3e7a4d9 100755 --- a/GameCenterManager Mac/AppDelegateMac.h +++ b/GameCenterManager Mac/AppDelegateMac.h @@ -7,10 +7,9 @@ // #import -#import "GameCenterManager-Mac.h" +#import "GameCenterManager.h" -@interface AppDelegateMac : NSObject +@interface AppDelegateMac : NSObject @property (assign) IBOutlet NSWindow *window; @property (strong) IBOutlet NSTextField *gcStatusTitle; diff --git a/GameCenterManager Mac/AppDelegateMac.m b/GameCenterManager Mac/AppDelegateMac.m index 4ddefff..cc49eb6 100755 --- a/GameCenterManager Mac/AppDelegateMac.m +++ b/GameCenterManager Mac/AppDelegateMac.m @@ -96,10 +96,6 @@ - (void)gameCenterManager:(GameCenterManager *)manager availabilityChanged:(NSDi } } -- (void)gameCenterManager:(GameCenterManager *)manager authenticateUser:(NSViewController *)gameCenterLoginController { - NSLog(@"Please Login"); -} - - (void)gameCenterManager:(GameCenterManager *)manager error:(NSDictionary *)error { NSLog(@"GC Error: %@", error); if ([[error objectForKey:@"error"] isEqualToString:@"Could not save achievement. Data missing."]) { @@ -107,36 +103,36 @@ - (void)gameCenterManager:(GameCenterManager *)manager error:(NSDictionary *)err } } -- (void)gameCenterManager:(GameCenterManager *)manager reportedScore:(NSDictionary *)scoreInformation { - NSLog(@"GC Reported Score: %@", scoreInformation); - gcActionInfo.stringValue = [NSString stringWithFormat:@"Reported leaderboard score to GameCenter."]; -} - -- (void)gameCenterManager:(GameCenterManager *)manager savedScore:(GKScore *)score { - NSLog(@"Saved GC Score with value: %lld", score.value); - gcActionInfo.stringValue = [NSString stringWithFormat:@"Score saved for upload to GameCenter."]; +- (void)gameCenterManager:(GameCenterManager *)manager reportedAchievement:(GKAchievement *)achievement withError:(NSError *)error { + if (!error) { + NSLog(@"GCM Reported Achievement: %@", achievement); + gcActionInfo.stringValue = [NSString stringWithFormat:@"Reported achievement with %.1f percent completed", achievement.percentComplete]; + } else { + NSLog(@"GCM Error while reporting achievement: %@", error); + } } -- (void)gameCenterManager:(GameCenterManager *)manager savedAchievement:(NSDictionary *)achievementInformation { - NSLog(@"Saved GC Achievement, %@", [achievementInformation objectForKey:@"id"]); - gcActionInfo.stringValue = [NSString stringWithFormat:@"Achievement saved for upload to GameCenter."]; +- (void)gameCenterManager:(GameCenterManager *)manager reportedScore:(GKScore *)score withError:(NSError *)error { + if (!error) { + NSLog(@"GCM Reported Score: %@", score); + gcActionInfo.stringValue = [NSString stringWithFormat:@"Reported leaderboard score: %lld", score.value]; + } else { + NSLog(@"GCM Error while reporting score: %@", error); + } } -- (void)gameCenterManager:(GameCenterManager *)manager reportedAchievement:(NSDictionary *)achievementInformation { - NSLog(@"GC Reported Achievement: %@", achievementInformation); - gcActionInfo.stringValue = [NSString stringWithFormat:@"Reported achievement to GameCenter."]; +- (void)gameCenterManager:(GameCenterManager *)manager didSaveScore:(GKScore *)score { + NSLog(@"Saved GCM Score with value: %lld", score.value); + gcActionInfo.stringValue = [NSString stringWithFormat:@"Score saved for upload to GameCenter."]; } -- (void)gameCenterManager:(GameCenterManager *)manager resetAchievements:(NSError *)error { - if (error) { - gcActionInfo.stringValue = [NSString stringWithFormat:@"Error reseting all GameCenter achievements."]; - } else { - gcActionInfo.stringValue = [NSString stringWithFormat:@"Reset all GameCenter achievements."]; - } +- (void)gameCenterManager:(GameCenterManager *)manager didSaveAchievement:(GKAchievement *)achievement { + NSLog(@"Saved GCM Achievement: %@", achievement); + gcActionInfo.stringValue = [NSString stringWithFormat:@"Achievement saved for upload to GameCenter."]; } - (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController { - + NSLog(@"%@ finished", gameCenterViewController); } //------------------------------------------------------------------------------------------------------------// @@ -204,7 +200,13 @@ - (void)achievementViewControllerDidFinish:(GKAchievementViewController *)viewCo } - (IBAction)resetAchievements:(id)sender { - [[GameCenterManager sharedManager] resetAchievements]; + [[GameCenterManager sharedManager] resetAchievementsWithCompletion:^(NSError *error) { + if (error) { + gcActionInfo.stringValue = [NSString stringWithFormat:@"Error reseting all GameCenter achievements."]; + } else { + gcActionInfo.stringValue = [NSString stringWithFormat:@"Reset all GameCenter achievements."]; + } + }]; } //------------------------------------------------------------------------------------------------------------// @@ -213,7 +215,7 @@ - (IBAction)resetAchievements:(id)sender { #pragma mark - GameCenter Challenges - (IBAction)loadChallenges:(id)sender { - //This feature is only supported in OS X 10.8.2 and higher + // This feature is only supported in OS X 10.8.2 and higher [[GameCenterManager sharedManager] getChallengesWithCompletion:^(NSArray *challenges, NSError *error) { gcActionInfo.stringValue = [NSString stringWithFormat:@"Loaded GameCenter challenges."]; NSLog(@"GC Challenges: %@", challenges); diff --git a/GameCenterManager Mac/GC Manager/GameCenterManager-Mac.h b/GameCenterManager Mac/GC Manager/GameCenterManager-Mac.h deleted file mode 100755 index 8140aba..0000000 --- a/GameCenterManager Mac/GC Manager/GameCenterManager-Mac.h +++ /dev/null @@ -1,117 +0,0 @@ -// -// GameCenterManager.h -// -// Created by iRare Media on 7/2/13. -// Copyright (c) 2013 iRare Media. 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 -#import -#import "Reachability.h" -#import "NSDataAES256.h" - -typedef enum GameCenterSortOrder { - GameCenterSortOrderHighToLow, - GameCenterSortOrderLowToHigh -} GameCenterSortOrder; - -enum { - GCMErrorUnknown = 1, - GCMErrorNotAvailable = 2, - GCMErrorChallengeNotAvailable = 3, - GCMErrorInternetNotAvailable = 4, - GCMErrorAchievementDataMissing = 5 -}; typedef NSInteger GCMErrorCode; - -@protocol GameCenterManagerDelegate; -@interface GameCenterManager : NSObject { - NSMutableArray *_leaderboards; -} - -// Sets up the Delegate -@property (nonatomic, weak) id 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. -- (void)saveAndReportScore:(int)score leaderboard:(NSString *)identifier sortOrder:(GameCenterSortOrder)order; - -/// Saves achievement locally and reports it to Game Center. If error occurs, achievement is saved to be submitted later. -- (void)saveAndReportAchievement:(NSString *)identifier percentComplete:(double)percentComplete shouldDisplayNotification:(BOOL)displayNotification; - -/// 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; - -/** Resets local player's achievements */ -- (void)resetAchievements; - -/// Returns currently authenticated local player. If no player is authenticated, "unknownPlayer" is returned. -- (NSString *)localPlayerId; -- (GKLocalPlayer *)localPlayerData; -- (void)localPlayerPhoto:(void (^)(NSImage *playerPhoto))handler; - -/** Checks for an active internet connection. - @return BOOL value, YES if an active internet connection is available, NO if there is no internet connection. - */ -- (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 Mac Delegate -@protocol GameCenterManagerDelegate -@optional -- (void)gameCenterManager:(GameCenterManager *)manager availabilityChanged:(NSDictionary *)availabilityInformation; -- (void)gameCenterManager:(GameCenterManager *)manager error:(NSError *)error; -- (void)gameCenterManager:(GameCenterManager *)manager reportedScore:(NSDictionary *)scoreInformation; -- (void)gameCenterManager:(GameCenterManager *)manager reportedAchievement:(NSDictionary *)achievementInformation; -- (void)gameCenterManager:(GameCenterManager *)manager savedScore:(GKScore *)score; -- (void)gameCenterManager:(GameCenterManager *)manager savedAchievement:(NSDictionary *)achievementInformation; -- (void)gameCenterManager:(GameCenterManager *)manager resetAchievements:(NSError *)error; -@end - - - diff --git a/GameCenterManager Mac/GC Manager/GameCenterManager-Mac.m b/GameCenterManager Mac/GC Manager/GameCenterManager-Mac.m deleted file mode 100755 index 99ffe3b..0000000 --- a/GameCenterManager Mac/GC Manager/GameCenterManager-Mac.m +++ /dev/null @@ -1,785 +0,0 @@ -// -// GameCenterManager.m -// -// Created by iRare Media on 7/2/13. -// Copyright (c) 2013 iRare Media. All rights reserved. -// - -#import "GameCenterManager-Mac.h" - - -//------------------------------------------------------------------------------------------------------------// -//------- GameCenter Manager Singleton -----------------------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark GameCenter Manager - -@implementation GameCenterManager -@synthesize isGameCenterAvailable, delegate; - -static GameCenterManager *sharedManager = nil; - -+ (GameCenterManager *)sharedManager { - if (sharedManager == nil) { - sharedManager = [[super allocWithZone:NULL] init]; - NSFileManager *fileManager = [NSFileManager defaultManager]; - if (![fileManager fileExistsAtPath:kGameCenterManagerDataPath]) { - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:dict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - } - - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - if (gameCenterManagerData == nil) { - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:dict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - - return sharedManager; -} - -+ (id)allocWithZone:(NSZone *)zone { - return [self sharedManager]; -} - -- (id)copyWithZone:(NSZone *)zone { - return self; -} - -//------------------------------------------------------------------------------------------------------------// -//------- GameCenter Manager Setup ---------------------------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark - GameCenter Manager Setup - -- (void)initGameCenter { - BOOL gameCenterAvailable = [self checkGameCenterAvailability]; - if (gameCenterAvailable) { - // Set GameCenter as available - [[GameCenterManager sharedManager] setIsGameCenterAvailable:YES]; - - if (![[NSUserDefaults standardUserDefaults] boolForKey:[@"scoresSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]] || - ![[NSUserDefaults standardUserDefaults] boolForKey:[@"achievementsSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]]) { - [[GameCenterManager sharedManager] syncGameCenter]; - } else { - [[GameCenterManager sharedManager] reportSavedScoresAndAchievements]; - } - - } else { - [[GameCenterManager sharedManager] setIsGameCenterAvailable:NO]; - } -} - -- (BOOL)checkGameCenterAvailability { - // First, check if the the GameKit Framework exists on the device. Return NO if it does not. - BOOL isGameCenterAPIAvailable = (NSClassFromString(@"GKLocalPlayer")) != nil; - - if (!isGameCenterAPIAvailable) { - NSDictionary *errorDictionary = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"GameKit Framework not available on this Mac. GameKit is only available on Macs with OS X 10.8.0 or higher.", @"GameCenter Unavailable", nil] - forKeys:[NSArray arrayWithObjects:@"message", @"title", nil]]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:availabilityChanged:)]) - [[self delegate] gameCenterManager:self availabilityChanged:errorDictionary]; - }); - - return NO; - - } else { - // The GameKit Framework is available. Now check if an internet connection can be established - BOOL internetAvailable = [self isInternetAvailable]; - if (!internetAvailable) { - NSDictionary *errorDictionary = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Cannot connect to the internet. Connect to the internet to establish a connection with GameCenter. Achievements and scores will still be saved locally and then uploaded later.", @"Internet Unavailable", nil] forKeys:[NSArray arrayWithObjects:@"message", @"title", nil]]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:availabilityChanged:)]) - [[self delegate] gameCenterManager:self availabilityChanged:errorDictionary]; - }); - - return NO; - - } else { - // The internet is available and the current device is connected. Now check if the player is authenticated - GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; - localPlayer.authenticateHandler = ^(NSViewController *viewController, NSError *error) { - if (viewController != nil) { - NSDictionary *errorDictionary = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Player is not yet signed into GameCenter. Please prompt the player using the authenticateUser delegate method.", @"No Player", nil] forKeys:[NSArray arrayWithObjects:@"message", @"title", nil]]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:availabilityChanged:)]) - [[self delegate] gameCenterManager:self availabilityChanged:errorDictionary]; - }); - } else if (!error) { - // Authentication handler completed successfully. Re-check availability - [self checkGameCenterAvailability]; - } - }; - - if (![[GKLocalPlayer localPlayer] isAuthenticated]) { - NSDictionary *errorDictionary = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Player is not signed into GameCenter, has declined to sign into GameCenter, or GameKit had an issue validating this game / app.", @"Player not Authenticated", nil] forKeys:[NSArray arrayWithObjects:@"message", @"title", nil]]; - - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:availabilityChanged:)]) - [[self delegate] gameCenterManager:self availabilityChanged:errorDictionary]; - - return NO; - - } else { - // The current player is logged into GameCenter - NSDictionary *successDictionary = [NSDictionary dictionaryWithObject:@"GameCenter Available" forKey:@"status"]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:availabilityChanged:)]) - [[self delegate] gameCenterManager:self availabilityChanged:successDictionary]; - }); - - self.isGameCenterAvailable = YES; - - return YES; - } - } - } -} - -// Check for internet with Reachability -- (BOOL)isInternetAvailable { - Reachability *reachability = [Reachability reachabilityForInternetConnection]; - NetworkStatus internetStatus = [reachability currentReachabilityStatus]; - - if (internetStatus == NotReachable) { - NSError *error = [NSError errorWithDomain:[NSString stringWithFormat:@"Internet unavailable - could not connect to the internet. Connect to WiFi or a Cellular Network to upload data to GameCenter."] code:GCMErrorInternetNotAvailable userInfo:nil]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - - return NO; - } else { - return YES; - } -} - -//------------------------------------------------------------------------------------------------------------// -//------- GameCenter Syncing ---------------------------------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark - GameCenter Syncing - -- (void)syncGameCenter { - // Begin Syncing with GameCenter - - // Check if GameCenter is available - if ([[GameCenterManager sharedManager] checkGameCenterAvailability] == YES) { - // Check if Leaderboard Scores are synced - if (![[NSUserDefaults standardUserDefaults] boolForKey:[@"scoresSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]]) { - if (_leaderboards == nil) { - [GKLeaderboard loadLeaderboardsWithCompletionHandler:^(NSArray *leaderboards, NSError *error) { - if (error == nil) { - _leaderboards = [[NSMutableArray alloc] initWithArray:leaderboards]; - [[GameCenterManager sharedManager] syncGameCenter]; - } else { - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - } - }]; - return; - } - - if (_leaderboards.count > 0) { - GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] initWithPlayerIDs:[NSArray arrayWithObject:[[GameCenterManager sharedManager] localPlayerId]]]; - [leaderboardRequest setCategory:[(GKLeaderboard *)[_leaderboards objectAtIndex:0] category]]; - [leaderboardRequest loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) { - if (error == nil) { - if (scores.count > 0) { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict == nil) { - playerDict = [NSMutableDictionary dictionary]; - } - - float savedHighScoreValue = 0; - NSNumber *savedHighScore = [playerDict objectForKey:leaderboardRequest.localPlayerScore.category]; - - if (savedHighScore != nil) { - savedHighScoreValue = [savedHighScore intValue]; - } - - [playerDict setObject:[NSNumber numberWithInt:MAX(leaderboardRequest.localPlayerScore.value, savedHighScoreValue)] - forKey:leaderboardRequest.localPlayerScore.category]; - [plistDict setObject:playerDict - forKey:[[GameCenterManager sharedManager] localPlayerId]]; - - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - - // Seeing an NSRangeException for an empty array when trying to remove the object - // Despite the check above in this scope that leaderboards count is > 0 - if (_leaderboards.count > 0) { - [_leaderboards removeObjectAtIndex:0]; - } - - [[GameCenterManager sharedManager] syncGameCenter]; - } else { - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - } - }]; - } else { - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:[@"scoresSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]]; - [[GameCenterManager sharedManager] syncGameCenter]; - } - - // Check if Achievements are synced - } else if (![[NSUserDefaults standardUserDefaults] boolForKey:[@"achievementsSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]]) { - [GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) { - if (error == nil) { - if (achievements.count > 0) { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict == nil) { - playerDict = [NSMutableDictionary dictionary]; - } - - for (GKAchievement *achievement in achievements) { - [playerDict setObject:[NSNumber numberWithDouble:achievement.percentComplete] forKey:achievement.identifier]; - } - - [plistDict setObject:playerDict forKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:[@"achievementsSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]]; - [[GameCenterManager sharedManager] syncGameCenter]; - } else { - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - } - }]; - } - } else { - NSError *error = [NSError errorWithDomain:[NSString stringWithFormat:@"GameCenter unavailable."] code:GCMErrorNotAvailable userInfo:nil]; - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - } -} - -// Report data when the internet is available again -- (void)reportSavedScoresAndAchievements { - if ([[GameCenterManager sharedManager] isInternetAvailable] == NO) { - return; - } - - GKScore *gkScore = nil; - - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableArray *savedScores = [plistDict objectForKey:@"SavedScores"]; - - if (savedScores != nil) { - if (savedScores.count > 0) { - gkScore = [NSKeyedUnarchiver unarchiveObjectWithData:[savedScores objectAtIndex:0]]; - - [savedScores removeObjectAtIndex:0]; - [plistDict setObject:savedScores forKey:@"SavedScores"]; - - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - } - - if (gkScore != nil) { - [gkScore reportScoreWithCompletionHandler:^(NSError *error) { - if (error == nil) { - [[GameCenterManager sharedManager] reportSavedScoresAndAchievements]; - } else { - [[GameCenterManager sharedManager] saveScoreToReportLater:gkScore]; - } - }]; - } else { - if ([GKLocalPlayer localPlayer].authenticated) { - NSString *identifier = nil; - double percentComplete = 0; - - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict != nil) { - NSMutableDictionary *savedAchievements = [playerDict objectForKey:@"SavedAchievements"]; - if (savedAchievements != nil) { - if (savedAchievements.count > 0) { - identifier = [[savedAchievements allKeys] objectAtIndex:0]; - percentComplete = [[savedAchievements objectForKey:identifier] doubleValue]; - - [savedAchievements removeObjectForKey:identifier]; - [playerDict setObject:savedAchievements forKey:@"SavedAchievements"]; - [plistDict setObject:playerDict forKey:[[GameCenterManager sharedManager] localPlayerId]]; - - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - } - } - - if (identifier != nil) { - GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier:identifier]; - achievement.percentComplete = percentComplete; - [achievement reportAchievementWithCompletionHandler:^(NSError *error) { - if (error == nil) { - [[GameCenterManager sharedManager] reportSavedScoresAndAchievements]; - } else { - [[GameCenterManager sharedManager] saveAchievementToReportLater:achievement.identifier percentComplete:achievement.percentComplete]; - } - }]; - } - } - } -} - - -//------------------------------------------------------------------------------------------------------------// -//------- Score and Achievement Reporting --------------------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark - Score and Achievement Reporting - -// Save score and report it to GameCenter -- (void)saveAndReportScore:(int)score leaderboard:(NSString *)identifier sortOrder:(GameCenterSortOrder)order { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict == nil) { - playerDict = [NSMutableDictionary dictionary]; - } - - NSNumber *savedHighScore = [playerDict objectForKey:identifier]; - if (savedHighScore == nil) { - savedHighScore = [NSNumber numberWithInt:0]; - } - - int savedHighScoreValue = [savedHighScore intValue]; - - // Determine if the new score is better than the old score - BOOL isScoreBetter = NO; - switch (order) { - case GameCenterSortOrderLowToHigh: // A lower score is better - if (score < savedHighScoreValue) { - isScoreBetter = YES; - } - break; - default: - if (score > savedHighScoreValue) { // A higher score is better - isScoreBetter = YES; - } - break; - } - - if (isScoreBetter) { - [playerDict setObject:[NSNumber numberWithInt:score] forKey:identifier]; - [plistDict setObject:playerDict forKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - - if ([[GameCenterManager sharedManager] checkGameCenterAvailability] == YES) { - GKScore *gkScore = [[GKScore alloc] initWithCategory:identifier]; - gkScore.value = score; - - [gkScore reportScoreWithCompletionHandler:^(NSError *error) { - NSDictionary *dict = nil; - - if (error == nil) { - dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:gkScore, nil] forKeys:[NSArray arrayWithObjects:@"score", nil]]; - } else { - dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:error.localizedDescription, gkScore, nil] forKeys:[NSArray arrayWithObjects:@"error", @"score", nil]]; - [[GameCenterManager sharedManager] saveScoreToReportLater:gkScore]; - } - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:reportedScore:)]) - [[self delegate] gameCenterManager:self reportedScore:dict]; - }); - }]; - } else { - GKScore *gkScore = [[GKScore alloc] initWithCategory:identifier]; - [[GameCenterManager sharedManager] saveScoreToReportLater:gkScore]; - } -} - -// Save achievement and report it to GameCenter -- (void)saveAndReportAchievement:(NSString *)identifier percentComplete:(double)percentComplete shouldDisplayNotification:(BOOL)displayNotification { - // Retrieve Saved Data - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - // Create the player dictionary - if (playerDict == nil) - playerDict = [NSMutableDictionary dictionary]; - - // Get the saved percent complete value - if it's nil, initialize it to 0, otherwise set it to its double value - NSNumber *savedPercentComplete = [playerDict objectForKey:identifier]; - if (savedPercentComplete == nil) savedPercentComplete = [NSNumber numberWithDouble:0]; - double savedPercentCompleteValue = [savedPercentComplete doubleValue]; - - // Compare the saved percent and the percent that was just submitted, if the submitted percent is greater save it - if (percentComplete > savedPercentCompleteValue) { - [playerDict setObject:[NSNumber numberWithDouble:percentComplete] forKey:identifier]; - [plistDict setObject:playerDict forKey:[[GameCenterManager sharedManager] localPlayerId]]; - - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - - // Check if GameCenter is Available - if ([[GameCenterManager sharedManager] checkGameCenterAvailability] == YES) { - // Create the Achievement Object - GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier:identifier]; - achievement.percentComplete = percentComplete; - - // Set whether or not a GameCenter achievement banner should be displayed - if (displayNotification == YES) { - achievement.showsCompletionBanner = YES; - } else { - achievement.showsCompletionBanner = NO; - } - - // Report the achievement to GameCenter - [achievement reportAchievementWithCompletionHandler:^(NSError *error) { - NSDictionary *dict = nil; - - if (error == nil) { - dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:achievement, nil] forKeys:[NSArray arrayWithObjects:@"achievement", nil]]; - } else { - if (achievement) { - dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:error.localizedDescription, achievement, nil] forKeys:[NSArray arrayWithObjects:@"error", @"achievement", nil]]; - } - - [[GameCenterManager sharedManager] saveAchievementToReportLater:identifier percentComplete:percentComplete]; - } - - // Notify the delegate on the main queue - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:reportedAchievement:)]) - [[self delegate] gameCenterManager:self reportedAchievement:dict]; - }); - - }]; - - } else { - // GameCenter is not available, just save the achievement for later - [[GameCenterManager sharedManager] saveAchievementToReportLater:identifier percentComplete:percentComplete]; - } -} - -// Save score to report later -- (void)saveScoreToReportLater:(GKScore *)score { - NSData *scoreData = [NSKeyedArchiver archivedDataWithRootObject:score]; - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableArray *savedScores = [plistDict objectForKey:@"SavedScores"]; - - if (savedScores != nil) { - [savedScores addObject:scoreData]; - } else { - savedScores = [NSMutableArray arrayWithObject:scoreData]; - } - - [plistDict setObject:savedScores forKey:@"SavedScores"]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:savedScore:)]) - [[self delegate] gameCenterManager:self savedScore:score]; - }); -} - -- (void)saveAchievementToReportLater:(NSString *)identifier percentComplete:(double)percentComplete { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict != nil) { - NSMutableDictionary *savedAchievements = [playerDict objectForKey:@"SavedAchievements"]; - if (savedAchievements != nil) { - double savedPercentCompleteValue = 0; - NSNumber *savedPercentComplete = [savedAchievements objectForKey:identifier]; - - if (savedPercentComplete != nil) { - savedPercentCompleteValue = [savedPercentComplete doubleValue]; - } - - // Compare the saved percent and the percent that was just submitted, if the submitted percent is greater save it - if (percentComplete > savedPercentCompleteValue) { - savedPercentComplete = [NSNumber numberWithDouble:percentComplete]; - [savedAchievements setObject:savedPercentComplete forKey:identifier]; - } - - } else { - savedAchievements = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithDouble:percentComplete], identifier, nil]; - [playerDict setObject:savedAchievements forKey:@"SavedAchievements"]; - } - } else { - NSMutableDictionary *savedAchievements = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithDouble:percentComplete], identifier, nil]; - playerDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:savedAchievements, @"SavedAchievements", nil]; - } - - [plistDict setObject:playerDict forKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - - GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier:identifier]; - NSNumber *percentNumber = [NSNumber numberWithDouble:percentComplete]; - - if (percentNumber && achievement) { - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:savedAchievement:)]) - [[self delegate] gameCenterManager:self savedAchievement:[NSDictionary dictionaryWithObjects:@[achievement, percentNumber] - forKeys:@[@"achievement", @"percent complete"]]]; - }); - } else { - NSError *error = [NSError errorWithDomain:[NSString stringWithFormat:@"Could not save achievement because necessary data is missing. GameCenter needs an Achievement ID and Percent Completed to save the achievement. You provided the following data:\nAchievement: %@\nPercent Completed:%@", achievement, percentNumber] - code:GCMErrorAchievementDataMissing userInfo:nil]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - } -} - -//------------------------------------------------------------------------------------------------------------// -//------- Score, Achievement, and Challenge Retrieval --------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark - Score, Achievement, and Challenge Retrieval - -- (int)highScoreForLeaderboard:(NSString *)identifier { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict != nil) { - NSNumber *savedHighScore = [playerDict objectForKey:identifier]; - if (savedHighScore != nil) { - return [savedHighScore intValue]; - } else { - return 0; - } - } else { - return 0; - } -} - -// Get leaderboard high scores -- (NSDictionary *)highScoreForLeaderboards:(NSArray *)identifiers { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSMutableDictionary *highScores = [[NSMutableDictionary alloc] initWithCapacity:identifiers.count]; - - for (NSString *identifier in identifiers) { - if (playerDict != nil) { - NSNumber *savedHighScore = [playerDict objectForKey:identifier]; - - if (savedHighScore != nil) { - [highScores setObject:[NSNumber numberWithInt:[savedHighScore intValue]] forKey:identifier]; - continue; - } - } - - [highScores setObject:[NSNumber numberWithInt:0] forKey:identifier]; - } - - NSDictionary *highScoreDict = [NSDictionary dictionaryWithDictionary:highScores]; - - return highScoreDict; -} - -// Get achievement progress -- (double)progressForAchievement:(NSString *)identifier { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict != nil) { - NSNumber *savedPercentComplete = [playerDict objectForKey:identifier]; - if (savedPercentComplete != nil) { - return [savedPercentComplete doubleValue]; - } - } - return 0; -} - -// Returns local player's percent completed for multiple achievements. -- (NSDictionary *)progressForAchievements:(NSArray *)identifiers { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSMutableDictionary *percent = [[NSMutableDictionary alloc] initWithCapacity:identifiers.count]; - - for (NSString *identifier in identifiers) { - if (playerDict != nil) { - NSNumber *savedPercentComplete = [playerDict objectForKey:identifier]; - - if (savedPercentComplete != nil) { - [percent setObject:[NSNumber numberWithDouble:[savedPercentComplete doubleValue]] forKey:identifier]; - continue; - } - } - - [percent setObject:[NSNumber numberWithDouble:0] forKey:identifier]; - } - - NSDictionary *percentDict = [NSDictionary dictionaryWithDictionary:percent]; - - return percentDict; -} - -// Returns local player's challenges for this game -- (void)getChallengesWithCompletion:(void (^)(NSArray *challenges, NSError *error))handler { - if ([[GameCenterManager sharedManager] checkGameCenterAvailability] == YES) { - BOOL isGameCenterChallengeAPIAvailable = (NSClassFromString(@"GKChallenge")) != nil; - - if (isGameCenterChallengeAPIAvailable == YES) { - [GKChallenge loadReceivedChallengesWithCompletionHandler:^(NSArray *challenges, NSError *error) { - if (error == nil) { - handler(challenges, nil); - } else { - handler(nil, error); - } - }]; - } else { - NSError *error = [NSError errorWithDomain:[NSString stringWithFormat:@"GKChallenge Class is not available. GKChallenge is only available on OS X 10.8.2 and higher."] - code:GCMErrorChallengeNotAvailable userInfo:nil]; - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - } - } else { - NSError *error = [NSError errorWithDomain:[NSString stringWithFormat:@"GameCenter Unavailable"] code:GCMErrorNotAvailable userInfo:nil]; - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - } -} - -//------------------------------------------------------------------------------------------------------------// -//------- Resetting Data -------------------------------------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark - Resetting Data - -// Reset all achievements and progress -- (void)resetAchievements { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSLog(@"PLIST: %@", plistDict); - - if ([[GameCenterManager sharedManager] isGameCenterAvailable]) { - [GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) { - if (error == nil) { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict == nil) { - playerDict = [NSMutableDictionary dictionary]; - } - - for (GKAchievement *achievement in achievements) { - [playerDict removeObjectForKey:achievement.identifier]; - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSLog(@"PLIST: %@", plistDict); - } - - [plistDict setObject:playerDict forKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - - [GKAchievement resetAchievementsWithCompletionHandler:^(NSError *error) { - if (error == nil) { - [[NSUserDefaults standardUserDefaults] setBool:NO forKey:[@"achievementsSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]]; - [[NSUserDefaults standardUserDefaults] synchronize]; - - [[GameCenterManager sharedManager] syncGameCenter]; - } - - dispatch_async(dispatch_get_main_queue(), ^{ - [self syncGameCenter]; - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:resetAchievements:)]) - [[self delegate] gameCenterManager:self resetAchievements:error]; - }); - }]; - } - }]; - } -} - -//------------------------------------------------------------------------------------------------------------// -//------- Player Data ----------------------------------------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark - Player Data - -// Checks if player is authenticated and gets his / her ID -- (NSString *)localPlayerId { - if ([[GameCenterManager sharedManager] isGameCenterAvailable] && [GKLocalPlayer localPlayer].authenticated) { - return [GKLocalPlayer localPlayer].playerID; - } - - return @"unknownPlayer"; -} - -// Returns the local player's display name -- (NSString *)localPlayerDisplayName { - if ([[GameCenterManager sharedManager] isGameCenterAvailable] && [GKLocalPlayer localPlayer].authenticated) { - if ([[GKLocalPlayer localPlayer] respondsToSelector:@selector(displayName)]) { - return [GKLocalPlayer localPlayer].displayName; - } else { - return [GKLocalPlayer localPlayer].alias; - } - } - - return @"unknownPlayer"; -} - -// Checks if player is authenticated and gets his / her ID -- (GKLocalPlayer *)localPlayerData { - if ([[GameCenterManager sharedManager] isGameCenterAvailable] && [GKLocalPlayer localPlayer].authenticated) { - return [GKLocalPlayer localPlayer]; - } - - return nil; -} - -- (void)localPlayerPhoto:(void (^)(NSImage *playerPhoto))handler { - if ([[GameCenterManager sharedManager] isGameCenterAvailable]) { - [[self localPlayerData] loadPhotoForSize:GKPhotoSizeNormal withCompletionHandler:^(NSImage *photo, NSError *error) { - handler(photo); - if (error) { - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - } - }]; - } else { - NSError *error = [NSError errorWithDomain:[NSString stringWithFormat:@"GameCenter Unavailable"] code:GCMErrorNotAvailable userInfo:nil]; - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - } -} - -@end \ No newline at end of file diff --git a/GameCenterManager Mac/GC Manager/NSDataAES256.h b/GameCenterManager Mac/GC Manager/NSDataAES256.h deleted file mode 100755 index 539abaf..0000000 --- a/GameCenterManager Mac/GC Manager/NSDataAES256.h +++ /dev/null @@ -1,12 +0,0 @@ -// -// NSDataAES256.h -// - -#import - -@interface NSData (AES256) - -- (NSData*) encryptedWithKey:(NSData*) key; -- (NSData*) decryptedWithKey:(NSData*) key; - -@end diff --git a/GameCenterManager Mac/GC Manager/NSDataAES256.m b/GameCenterManager Mac/GC Manager/NSDataAES256.m deleted file mode 100755 index 70dad35..0000000 --- a/GameCenterManager Mac/GC Manager/NSDataAES256.m +++ /dev/null @@ -1,70 +0,0 @@ -// -// NSDataAES256.m -// - -#import "NSDataAES256.h" -#import - -// Key size is 32 bytes for AES256 -#define kKeySize kCCKeySizeAES256 - -@implementation NSData (AES256) - -- (NSData *)makeCryptedVersionWithKeyData:(const void*) keyData ofLength:(NSUInteger) keyLength decrypt:(bool) decrypt { - // Copy the key data, padding with zeroes if needed - char key[kKeySize]; - bzero(key, sizeof(key)); - memcpy(key, keyData, keyLength > kKeySize ? kKeySize : keyLength); - - size_t bufferSize = [self length] + kCCBlockSizeAES128; - void* buffer = malloc(bufferSize); - - size_t dataUsed; - - CCCryptorStatus status = CCCrypt(decrypt ? kCCDecrypt : kCCEncrypt, - kCCAlgorithmAES128, - kCCOptionPKCS7Padding | kCCOptionECBMode, - key, kKeySize, - NULL, - [self bytes], [self length], - buffer, bufferSize, - &dataUsed); - - switch(status) { - case kCCSuccess: - return [NSData dataWithBytesNoCopy:buffer length:dataUsed]; - case kCCParamError: - NSLog(@"Error: NSDataAES256: Could not %s data: Param error", decrypt ? "decrypt" : "encrypt"); - break; - case kCCBufferTooSmall: - NSLog(@"Error: NSDataAES256: Could not %s data: Buffer too small", decrypt ? "decrypt" : "encrypt"); - break; - case kCCMemoryFailure: - NSLog(@"Error: NSDataAES256: Could not %s data: Memory failure", decrypt ? "decrypt" : "encrypt"); - break; - case kCCAlignmentError: - NSLog(@"Error: NSDataAES256: Could not %s data: Alignment error", decrypt ? "decrypt" : "encrypt"); - break; - case kCCDecodeError: - NSLog(@"Error: NSDataAES256: Could not %s data: Decode error", decrypt ? "decrypt" : "encrypt"); - break; - case kCCUnimplemented: - NSLog(@"Error: NSDataAES256: Could not %s data: Unimplemented", decrypt ? "decrypt" : "encrypt"); - break; - default: - NSLog(@"Error: NSDataAES256: Could not %s data: Unknown error", decrypt ? "decrypt" : "encrypt"); - } - - free(buffer); - return nil; -} - -- (NSData *)encryptedWithKey:(NSData *)key { - return [self makeCryptedVersionWithKeyData:[key bytes] ofLength:[key length] decrypt:NO]; -} - -- (NSData* )decryptedWithKey:(NSData *)key { - return [self makeCryptedVersionWithKeyData:[key bytes] ofLength:[key length] decrypt:YES]; -} - -@end diff --git a/GameCenterManager Mac/GC Manager/Reachability.h b/GameCenterManager Mac/GC Manager/Reachability.h deleted file mode 100755 index 9febed8..0000000 --- a/GameCenterManager Mac/GC Manager/Reachability.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - Copyright (c) 2011, Tony Million. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ - -#import -#import - -#import -#import -#import -#import -#import -#import - -/** - * Does ARC support support GCD objects? - * It does if the minimum deployment target is iOS 6+ or Mac OS X 8+ - * - * @see http://opensource.apple.com/source/libdispatch/libdispatch-228.18/os/object.h - **/ -#if OS_OBJECT_USE_OBJC -#define NEEDS_DISPATCH_RETAIN_RELEASE 0 -#else -#define NEEDS_DISPATCH_RETAIN_RELEASE 1 -#endif - - -extern NSString *const kReachabilityChangedNotification; - -typedef enum -{ - // Apple NetworkStatus Compatible Names. - NotReachable = 0, - ReachableViaWiFi = 2, - ReachableViaWWAN = 1 -} NetworkStatus; - -@class Reachability; - -typedef void (^NetworkReachable)(Reachability * reachability); -typedef void (^NetworkUnreachable)(Reachability * reachability); - -@interface Reachability : NSObject - -@property (nonatomic, copy) NetworkReachable reachableBlock; -@property (nonatomic, copy) NetworkUnreachable unreachableBlock; - - -@property (nonatomic, assign) BOOL reachableOnWWAN; - -+(Reachability*)reachabilityWithHostname:(NSString*)hostname; -+(Reachability*)reachabilityForInternetConnection; -+(Reachability*)reachabilityWithAddress:(const struct sockaddr_in*)hostAddress; -+(Reachability*)reachabilityForLocalWiFi; - --(Reachability *)initWithReachabilityRef:(SCNetworkReachabilityRef)ref; - --(BOOL)startNotifier; --(void)stopNotifier; - --(BOOL)isReachable; --(BOOL)isReachableViaWWAN; --(BOOL)isReachableViaWiFi; - -// WWAN may be available, but not active until a connection has been established. -// WiFi may require a connection for VPN on Demand. --(BOOL)isConnectionRequired; // Identical DDG variant. --(BOOL)connectionRequired; // Apple's routine. -// Dynamic, on demand connection? --(BOOL)isConnectionOnDemand; -// Is user intervention required? --(BOOL)isInterventionRequired; - --(NetworkStatus)currentReachabilityStatus; --(SCNetworkReachabilityFlags)reachabilityFlags; --(NSString*)currentReachabilityString; --(NSString*)currentReachabilityFlags; - -@end diff --git a/GameCenterManager Mac/GC Manager/Reachability.m b/GameCenterManager Mac/GC Manager/Reachability.m deleted file mode 100755 index 348b33e..0000000 --- a/GameCenterManager Mac/GC Manager/Reachability.m +++ /dev/null @@ -1,519 +0,0 @@ -/* - Copyright (c) 2011, Tony Million. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ - -#import "Reachability.h" - - -NSString *const kReachabilityChangedNotification = @"kReachabilityChangedNotification"; - -@interface Reachability () - -@property (nonatomic, assign) SCNetworkReachabilityRef reachabilityRef; - - -#if NEEDS_DISPATCH_RETAIN_RELEASE -@property (nonatomic, assign) dispatch_queue_t reachabilitySerialQueue; -#else -@property (nonatomic, strong) dispatch_queue_t reachabilitySerialQueue; -#endif - - -@property (nonatomic, strong) id reachabilityObject; - --(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags; --(BOOL)isReachableWithFlags:(SCNetworkReachabilityFlags)flags; - -@end - -static NSString *reachabilityFlags(SCNetworkReachabilityFlags flags) -{ - return [NSString stringWithFormat:@"%c%c %c%c%c%c%c%c%c", -#if TARGET_OS_IPHONE - (flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-', -#else - 'X', -#endif - (flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-', - (flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-', - (flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-', - (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-', - (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-', - (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-', - (flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-', - (flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-']; -} - -//Start listening for reachability notifications on the current run loop -static void TMReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) -{ -#pragma unused (target) -#if __has_feature(objc_arc) - Reachability *reachability = ((__bridge Reachability*)info); -#else - Reachability *reachability = ((Reachability*)info); -#endif - - // we probably dont need an autoreleasepool here as GCD docs state each queue has its own autorelease pool - // but what the heck eh? - @autoreleasepool - { - [reachability reachabilityChanged:flags]; - } -} - - -@implementation Reachability - -@synthesize reachabilityRef; -@synthesize reachabilitySerialQueue; - -@synthesize reachableOnWWAN; - -@synthesize reachableBlock; -@synthesize unreachableBlock; - -@synthesize reachabilityObject; - -#pragma mark - class constructor methods -+(Reachability*)reachabilityWithHostname:(NSString*)hostname -{ - SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithName(NULL, [hostname UTF8String]); - if (ref) - { - id reachability = [[self alloc] initWithReachabilityRef:ref]; - -#if __has_feature(objc_arc) - return reachability; -#else - return [reachability autorelease]; -#endif - - } - - return nil; -} - -+(Reachability *)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress -{ - SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress); - if (ref) - { - id reachability = [[self alloc] initWithReachabilityRef:ref]; - -#if __has_feature(objc_arc) - return reachability; -#else - return [reachability autorelease]; -#endif - } - - return nil; -} - -+(Reachability *)reachabilityForInternetConnection -{ - struct sockaddr_in zeroAddress; - bzero(&zeroAddress, sizeof(zeroAddress)); - zeroAddress.sin_len = sizeof(zeroAddress); - zeroAddress.sin_family = AF_INET; - - return [self reachabilityWithAddress:&zeroAddress]; -} - -+(Reachability*)reachabilityForLocalWiFi -{ - struct sockaddr_in localWifiAddress; - bzero(&localWifiAddress, sizeof(localWifiAddress)); - localWifiAddress.sin_len = sizeof(localWifiAddress); - localWifiAddress.sin_family = AF_INET; - // IN_LINKLOCALNETNUM is defined in as 169.254.0.0 - localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM); - - return [self reachabilityWithAddress:&localWifiAddress]; -} - - -// initialization methods - --(Reachability *)initWithReachabilityRef:(SCNetworkReachabilityRef)ref -{ - self = [super init]; - if (self != nil) - { - self.reachableOnWWAN = YES; - self.reachabilityRef = ref; - } - - return self; -} - --(void)dealloc -{ - [self stopNotifier]; - - if(self.reachabilityRef) - { - CFRelease(self.reachabilityRef); - self.reachabilityRef = nil; - } - - -#if !(__has_feature(objc_arc)) - [super dealloc]; -#endif - - -} - -#pragma mark - notifier methods - -// Notifier -// NOTE: this uses GCD to trigger the blocks - they *WILL NOT* be called on THE MAIN THREAD -// - In other words DO NOT DO ANY UI UPDATES IN THE BLOCKS. -// INSTEAD USE dispatch_async(dispatch_get_main_queue(), ^{UISTUFF}) (or dispatch_sync if you want) - --(BOOL)startNotifier -{ - SCNetworkReachabilityContext context = { 0, NULL, NULL, NULL, NULL }; - - // this should do a retain on ourself, so as long as we're in notifier mode we shouldn't disappear out from under ourselves - // woah - self.reachabilityObject = self; - - - - // first we need to create a serial queue - // we allocate this once for the lifetime of the notifier - self.reachabilitySerialQueue = dispatch_queue_create("com.tonymillion.reachability", NULL); - if(!self.reachabilitySerialQueue) - { - return NO; - } - -#if __has_feature(objc_arc) - context.info = (__bridge void *)self; -#else - context.info = (void *)self; -#endif - - if (!SCNetworkReachabilitySetCallback(self.reachabilityRef, TMReachabilityCallback, &context)) - { -#ifdef DEBUG - NSLog(@"SCNetworkReachabilitySetCallback() failed: %s", SCErrorString(SCError())); -#endif - - //clear out the dispatch queue - if(self.reachabilitySerialQueue) - { -#if NEEDS_DISPATCH_RETAIN_RELEASE - dispatch_release(self.reachabilitySerialQueue); -#endif - self.reachabilitySerialQueue = nil; - } - - self.reachabilityObject = nil; - - return NO; - } - - // set it as our reachability queue which will retain the queue - if(!SCNetworkReachabilitySetDispatchQueue(self.reachabilityRef, self.reachabilitySerialQueue)) - { -#ifdef DEBUG - NSLog(@"SCNetworkReachabilitySetDispatchQueue() failed: %s", SCErrorString(SCError())); -#endif - - //UH OH - FAILURE! - - // first stop any callbacks! - SCNetworkReachabilitySetCallback(self.reachabilityRef, NULL, NULL); - - // then clear out the dispatch queue - if(self.reachabilitySerialQueue) - { -#if NEEDS_DISPATCH_RETAIN_RELEASE - dispatch_release(self.reachabilitySerialQueue); -#endif - self.reachabilitySerialQueue = nil; - } - - self.reachabilityObject = nil; - - return NO; - } - - return YES; -} - --(void)stopNotifier -{ - // first stop any callbacks! - SCNetworkReachabilitySetCallback(self.reachabilityRef, NULL, NULL); - - // unregister target from the GCD serial dispatch queue - SCNetworkReachabilitySetDispatchQueue(self.reachabilityRef, NULL); - - if(self.reachabilitySerialQueue) - { -#if NEEDS_DISPATCH_RETAIN_RELEASE - dispatch_release(self.reachabilitySerialQueue); -#endif - self.reachabilitySerialQueue = nil; - } - - self.reachabilityObject = nil; -} - -#pragma mark - reachability tests - -// this is for the case where you flick the airplane mode -// you end up getting something like this: -//Reachability: WR ct----- -//Reachability: -- ------- -//Reachability: WR ct----- -//Reachability: -- ------- -// we treat this as 4 UNREACHABLE triggers - really apple should do better than this - -#define testcase (kSCNetworkReachabilityFlagsConnectionRequired | kSCNetworkReachabilityFlagsTransientConnection) - --(BOOL)isReachableWithFlags:(SCNetworkReachabilityFlags)flags -{ - BOOL connectionUP = YES; - - if(!(flags & kSCNetworkReachabilityFlagsReachable)) - connectionUP = NO; - - if( (flags & testcase) == testcase ) - connectionUP = NO; - -#if TARGET_OS_IPHONE - if(flags & kSCNetworkReachabilityFlagsIsWWAN) - { - // we're on 3G - if(!self.reachableOnWWAN) - { - // we dont want to connect when on 3G - connectionUP = NO; - } - } -#endif - - return connectionUP; -} - --(BOOL)isReachable -{ - SCNetworkReachabilityFlags flags; - - if(!SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) - return NO; - - return [self isReachableWithFlags:flags]; -} - --(BOOL)isReachableViaWWAN -{ -#if TARGET_OS_IPHONE - - SCNetworkReachabilityFlags flags = 0; - - if(SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) - { - // check we're REACHABLE - if(flags & kSCNetworkReachabilityFlagsReachable) - { - // now, check we're on WWAN - if(flags & kSCNetworkReachabilityFlagsIsWWAN) - { - return YES; - } - } - } -#endif - - return NO; -} - --(BOOL)isReachableViaWiFi -{ - SCNetworkReachabilityFlags flags = 0; - - if(SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) - { - // check we're reachable - if((flags & kSCNetworkReachabilityFlagsReachable)) - { -#if TARGET_OS_IPHONE - // check we're NOT on WWAN - if((flags & kSCNetworkReachabilityFlagsIsWWAN)) - { - return NO; - } -#endif - return YES; - } - } - - return NO; -} - - -// WWAN may be available, but not active until a connection has been established. -// WiFi may require a connection for VPN on Demand. --(BOOL)isConnectionRequired -{ - return [self connectionRequired]; -} - --(BOOL)connectionRequired -{ - SCNetworkReachabilityFlags flags; - - if(SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) - { - return (flags & kSCNetworkReachabilityFlagsConnectionRequired); - } - - return NO; -} - -// Dynamic, on demand connection? --(BOOL)isConnectionOnDemand -{ - SCNetworkReachabilityFlags flags; - - if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) - { - return ((flags & kSCNetworkReachabilityFlagsConnectionRequired) && - (flags & (kSCNetworkReachabilityFlagsConnectionOnTraffic | kSCNetworkReachabilityFlagsConnectionOnDemand))); - } - - return NO; -} - -// Is user intervention required? --(BOOL)isInterventionRequired -{ - SCNetworkReachabilityFlags flags; - - if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) - { - return ((flags & kSCNetworkReachabilityFlagsConnectionRequired) && - (flags & kSCNetworkReachabilityFlagsInterventionRequired)); - } - - return NO; -} - - -#pragma mark - reachability status stuff - --(NetworkStatus)currentReachabilityStatus -{ - if([self isReachable]) - { - if([self isReachableViaWiFi]) - return ReachableViaWiFi; - -#if TARGET_OS_IPHONE - return ReachableViaWWAN; -#endif - } - - return NotReachable; -} - --(SCNetworkReachabilityFlags)reachabilityFlags -{ - SCNetworkReachabilityFlags flags = 0; - - if(SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) - { - return flags; - } - - return 0; -} - --(NSString*)currentReachabilityString -{ - NetworkStatus temp = [self currentReachabilityStatus]; - - if(temp == reachableOnWWAN) - { - // updated for the fact we have CDMA phones now! - return NSLocalizedString(@"Cellular", @""); - } - if (temp == ReachableViaWiFi) - { - return NSLocalizedString(@"WiFi", @""); - } - - return NSLocalizedString(@"No Connection", @""); -} - --(NSString*)currentReachabilityFlags -{ - return reachabilityFlags([self reachabilityFlags]); -} - -#pragma mark - callback function calls this method - --(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags -{ - if([self isReachableWithFlags:flags]) - { - if(self.reachableBlock) - { - self.reachableBlock(self); - } - } - else - { - if(self.unreachableBlock) - { - self.unreachableBlock(self); - } - } - - // this makes sure the change notification happens on the MAIN THREAD - dispatch_async(dispatch_get_main_queue(), ^{ - [[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification - object:self]; - }); -} - -#pragma mark - Debug Description - -- (NSString *) description; -{ - NSString *description = [NSString stringWithFormat:@"<%@: %#x>", - NSStringFromClass([self class]), (unsigned int) self]; - return description; -} - -@end diff --git a/GameCenterManager Mac/GameCenterManager Mac-Info.plist b/GameCenterManager Mac/GameCenterManager Mac-Info.plist index 1075f28..b9191cc 100755 --- a/GameCenterManager Mac/GameCenterManager Mac-Info.plist +++ b/GameCenterManager Mac/GameCenterManager Mac-Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 5.1 + 5.2 CFBundleSignature ???? CFBundleVersion - 5.1 + 5.2 LSApplicationCategoryType public.app-category.games LSMinimumSystemVersion diff --git a/GameCenterManager Mac/New icon-32@2x.png b/GameCenterManager Mac/New icon-32@2x.png deleted file mode 100755 index 30ac6e0..0000000 Binary files a/GameCenterManager Mac/New icon-32@2x.png and /dev/null differ diff --git a/GameCenterManager Mac/New icon-512@2x.png b/GameCenterManager Mac/New icon-512@2x.png deleted file mode 100755 index 96a2159..0000000 Binary files a/GameCenterManager Mac/New icon-512@2x.png and /dev/null differ diff --git a/GameCenterManager.xcodeproj/project.pbxproj b/GameCenterManager.xcodeproj/project.pbxproj index 8041433..f631753 100755 --- a/GameCenterManager.xcodeproj/project.pbxproj +++ b/GameCenterManager.xcodeproj/project.pbxproj @@ -16,6 +16,11 @@ 659699EE1515718800724EBE /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 659699ED1515718800724EBE /* ViewController.m */; }; 65969A06151572D800724EBE /* GameKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65969A05151572D800724EBE /* GameKit.framework */; }; 65969A0B1515748900724EBE /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65969A0A1515748900724EBE /* SystemConfiguration.framework */; }; + 993EFA171847C2E30061C758 /* GameCenterManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 99B16C22172D71130091618D /* GameCenterManager.m */; }; + 993EFA181847C37A0061C758 /* NSDataAES256.m in Sources */ = {isa = PBXBuildFile; fileRef = 99B16C24172D71130091618D /* NSDataAES256.m */; }; + 993EFA191847C37E0061C758 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 99B16C26172D71130091618D /* Reachability.m */; }; + 993EFA1B1847C54A0061C758 /* Changelog.md in Resources */ = {isa = PBXBuildFile; fileRef = 993EFA1A1847C54A0061C758 /* Changelog.md */; }; + 993EFA1D1847C55A0061C758 /* Interface.png in Resources */ = {isa = PBXBuildFile; fileRef = 993EFA1C1847C55A0061C758 /* Interface.png */; }; 994B764E17EE2F3D008DE309 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 994B764C17EE282F008DE309 /* Images.xcassets */; }; 994B764F17EE2F47008DE309 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 994B764C17EE282F008DE309 /* Images.xcassets */; }; 994E294C17838BF300EAACD2 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 994E294A17838BF300EAACD2 /* InfoPlist.strings */; }; @@ -27,12 +32,6 @@ 994E296117838C4100EAACD2 /* GameKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 994E296017838C4100EAACD2 /* GameKit.framework */; }; 994E296317838C4F00EAACD2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 994E296217838C4F00EAACD2 /* Foundation.framework */; }; 994E296517838C5A00EAACD2 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 994E296417838C5A00EAACD2 /* SystemConfiguration.framework */; }; - 994E29701783919400EAACD2 /* GameCenterManager-Mac.m in Sources */ = {isa = PBXBuildFile; fileRef = 994E296B1783919400EAACD2 /* GameCenterManager-Mac.m */; }; - 994E29711783919400EAACD2 /* NSDataAES256.m in Sources */ = {isa = PBXBuildFile; fileRef = 994E296D1783919400EAACD2 /* NSDataAES256.m */; }; - 994E29721783919400EAACD2 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 994E296F1783919400EAACD2 /* Reachability.m */; }; - 994E29751783D05B00EAACD2 /* FeltTile.png in Resources */ = {isa = PBXBuildFile; fileRef = 994E29741783D05B00EAACD2 /* FeltTile.png */; }; - 994E29771783D68500EAACD2 /* TopBar.png in Resources */ = {isa = PBXBuildFile; fileRef = 994E29761783D68500EAACD2 /* TopBar.png */; }; - 994E29791783DC6200EAACD2 /* MacHeader.png in Resources */ = {isa = PBXBuildFile; fileRef = 994E29781783DC6200EAACD2 /* MacHeader.png */; }; 99B16C18172D46180091618D /* Storyboard_iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 99B16C16172D46180091618D /* Storyboard_iPhone.storyboard */; }; 99B16C1E172D70AB0091618D /* License.md in Resources */ = {isa = PBXBuildFile; fileRef = 99B16C1C172D70AB0091618D /* License.md */; }; 99B16C1F172D70AB0091618D /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 99B16C1D172D70AB0091618D /* README.md */; }; @@ -56,7 +55,9 @@ 659699ED1515718800724EBE /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 65969A05151572D800724EBE /* GameKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameKit.framework; path = System/Library/Frameworks/GameKit.framework; sourceTree = SDKROOT; }; 65969A0A1515748900724EBE /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; - 994B764C17EE282F008DE309 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = GameCenterManager/Images.xcassets; sourceTree = ""; }; + 993EFA1A1847C54A0061C758 /* Changelog.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Changelog.md; sourceTree = ""; }; + 993EFA1C1847C55A0061C758 /* Interface.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Interface.png; sourceTree = ""; }; + 994B764C17EE282F008DE309 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 994E294017838BF300EAACD2 /* GameCenterManager Mac.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "GameCenterManager Mac.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 994E294417838BF300EAACD2 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; 994E294517838BF300EAACD2 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; @@ -73,24 +74,15 @@ 994E296017838C4100EAACD2 /* GameKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/GameKit.framework; sourceTree = DEVELOPER_DIR; }; 994E296217838C4F00EAACD2 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; 994E296417838C5A00EAACD2 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/SystemConfiguration.framework; sourceTree = DEVELOPER_DIR; }; - 994E296A1783919400EAACD2 /* GameCenterManager-Mac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GameCenterManager-Mac.h"; sourceTree = ""; }; - 994E296B1783919400EAACD2 /* GameCenterManager-Mac.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GameCenterManager-Mac.m"; sourceTree = ""; }; - 994E296C1783919400EAACD2 /* NSDataAES256.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSDataAES256.h; sourceTree = ""; }; - 994E296D1783919400EAACD2 /* NSDataAES256.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSDataAES256.m; sourceTree = ""; }; - 994E296E1783919400EAACD2 /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = ""; }; - 994E296F1783919400EAACD2 /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = ""; }; - 994E29741783D05B00EAACD2 /* FeltTile.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = FeltTile.png; sourceTree = ""; }; - 994E29761783D68500EAACD2 /* TopBar.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = TopBar.png; sourceTree = ""; }; - 994E29781783DC6200EAACD2 /* MacHeader.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = MacHeader.png; sourceTree = ""; }; 99B16C17172D46180091618D /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/Storyboard_iPhone.storyboard; sourceTree = ""; }; 99B16C1C172D70AB0091618D /* License.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = License.md; sourceTree = ""; }; 99B16C1D172D70AB0091618D /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = ""; }; - 99B16C21172D71130091618D /* GameCenterManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GameCenterManager.h; path = "GC Manager/GameCenterManager.h"; sourceTree = ""; }; - 99B16C22172D71130091618D /* GameCenterManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GameCenterManager.m; path = "GC Manager/GameCenterManager.m"; sourceTree = ""; }; - 99B16C23172D71130091618D /* NSDataAES256.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NSDataAES256.h; path = "GC Manager/NSDataAES256.h"; sourceTree = ""; }; - 99B16C24172D71130091618D /* NSDataAES256.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NSDataAES256.m; path = "GC Manager/NSDataAES256.m"; sourceTree = ""; }; - 99B16C25172D71130091618D /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Reachability.h; path = "GC Manager/Reachability.h"; sourceTree = ""; }; - 99B16C26172D71130091618D /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Reachability.m; path = "GC Manager/Reachability.m"; sourceTree = ""; }; + 99B16C21172D71130091618D /* GameCenterManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameCenterManager.h; sourceTree = ""; }; + 99B16C22172D71130091618D /* GameCenterManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameCenterManager.m; sourceTree = ""; }; + 99B16C23172D71130091618D /* NSDataAES256.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSDataAES256.h; sourceTree = ""; }; + 99B16C24172D71130091618D /* NSDataAES256.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSDataAES256.m; sourceTree = ""; }; + 99B16C25172D71130091618D /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = ""; }; + 99B16C26172D71130091618D /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -124,9 +116,12 @@ isa = PBXGroup; children = ( 99B16C1D172D70AB0091618D /* README.md */, + 993EFA1A1847C54A0061C758 /* Changelog.md */, 99B16C1C172D70AB0091618D /* License.md */, + 993EFA1C1847C55A0061C758 /* Interface.png */, 994B764C17EE282F008DE309 /* Images.xcassets */, - 659699E01515718800724EBE /* GameCenterManager */, + 99B16C20172D71090091618D /* GC Manager */, + 659699E01515718800724EBE /* GameCenterManager iOS */, 994E294717838BF300EAACD2 /* GameCenterManager Mac */, 659699D91515718800724EBE /* Frameworks */, 659699D71515718800724EBE /* Products */, @@ -152,10 +147,9 @@ name = Frameworks; sourceTree = ""; }; - 659699E01515718800724EBE /* GameCenterManager */ = { + 659699E01515718800724EBE /* GameCenterManager iOS */ = { isa = PBXGroup; children = ( - 99B16C20172D71090091618D /* GC Manager */, 659699E91515718800724EBE /* AppDelegate.h */, 659699EA1515718800724EBE /* AppDelegate.m */, 659699EC1515718800724EBE /* ViewController.h */, @@ -163,6 +157,7 @@ 99B16C16172D46180091618D /* Storyboard_iPhone.storyboard */, 659699E11515718800724EBE /* Supporting Files */, ); + name = "GameCenterManager iOS"; path = GameCenterManager; sourceTree = ""; }; @@ -171,8 +166,8 @@ children = ( 659699E21515718800724EBE /* GameCenterManager-Info.plist */, 659699E31515718800724EBE /* InfoPlist.strings */, - 659699E61515718800724EBE /* main.m */, 659699E81515718800724EBE /* GameCenterManager-Prefix.pch */, + 659699E61515718800724EBE /* main.m */, ); name = "Supporting Files"; sourceTree = ""; @@ -190,8 +185,6 @@ 994E294717838BF300EAACD2 /* GameCenterManager Mac */ = { isa = PBXGroup; children = ( - 994E29691783919400EAACD2 /* GC Manager */, - 994E29731783D05B00EAACD2 /* Images */, 994E295317838BF300EAACD2 /* AppDelegateMac.h */, 994E295417838BF300EAACD2 /* AppDelegateMac.m */, 994E295617838BF300EAACD2 /* MainMenu.xib */, @@ -205,9 +198,9 @@ children = ( 994E294917838BF300EAACD2 /* GameCenterManager Mac-Info.plist */, 994E294A17838BF300EAACD2 /* InfoPlist.strings */, - 994E294D17838BF300EAACD2 /* main.m */, - 994E294F17838BF300EAACD2 /* GameCenterManager Mac-Prefix.pch */, 994E295017838BF300EAACD2 /* Credits.rtf */, + 994E294F17838BF300EAACD2 /* GameCenterManager Mac-Prefix.pch */, + 994E294D17838BF300EAACD2 /* main.m */, ); name = "Supporting Files"; sourceTree = ""; @@ -235,26 +228,6 @@ name = "OS X"; sourceTree = ""; }; - 994E29691783919400EAACD2 /* GC Manager */ = { - isa = PBXGroup; - children = ( - 994E296A1783919400EAACD2 /* GameCenterManager-Mac.h */, - 994E296B1783919400EAACD2 /* GameCenterManager-Mac.m */, - 99DD76A9178497AD00353229 /* Dependencies */, - ); - path = "GC Manager"; - sourceTree = ""; - }; - 994E29731783D05B00EAACD2 /* Images */ = { - isa = PBXGroup; - children = ( - 994E29781783DC6200EAACD2 /* MacHeader.png */, - 994E29761783D68500EAACD2 /* TopBar.png */, - 994E29741783D05B00EAACD2 /* FeltTile.png */, - ); - path = Images; - sourceTree = ""; - }; 99B0162C1754FD7700F56A5C /* Dependencies */ = { isa = PBXGroup; children = ( @@ -289,18 +262,7 @@ 99B16C21172D71130091618D /* GameCenterManager.h */, 99B16C22172D71130091618D /* GameCenterManager.m */, ); - name = "GC Manager"; - sourceTree = ""; - }; - 99DD76A9178497AD00353229 /* Dependencies */ = { - isa = PBXGroup; - children = ( - 994E296C1783919400EAACD2 /* NSDataAES256.h */, - 994E296D1783919400EAACD2 /* NSDataAES256.m */, - 994E296E1783919400EAACD2 /* Reachability.h */, - 994E296F1783919400EAACD2 /* Reachability.m */, - ); - name = Dependencies; + path = "GC Manager"; sourceTree = ""; }; /* End PBXGroup section */ @@ -381,10 +343,12 @@ buildActionMask = 2147483647; files = ( 659699E51515718800724EBE /* InfoPlist.strings in Resources */, + 993EFA1D1847C55A0061C758 /* Interface.png in Resources */, 994B764F17EE2F47008DE309 /* Images.xcassets in Resources */, 99B16C18172D46180091618D /* Storyboard_iPhone.storyboard in Resources */, 99B16C1E172D70AB0091618D /* License.md in Resources */, 99B16C1F172D70AB0091618D /* README.md in Resources */, + 993EFA1B1847C54A0061C758 /* Changelog.md in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -396,9 +360,6 @@ 994B764E17EE2F3D008DE309 /* Images.xcassets in Resources */, 994E295217838BF300EAACD2 /* Credits.rtf in Resources */, 994E295817838BF300EAACD2 /* MainMenu.xib in Resources */, - 994E29751783D05B00EAACD2 /* FeltTile.png in Resources */, - 994E29771783D68500EAACD2 /* TopBar.png in Resources */, - 994E29791783DC6200EAACD2 /* MacHeader.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -424,9 +385,9 @@ files = ( 994E294E17838BF300EAACD2 /* main.m in Sources */, 994E295517838BF300EAACD2 /* AppDelegateMac.m in Sources */, - 994E29701783919400EAACD2 /* GameCenterManager-Mac.m in Sources */, - 994E29711783919400EAACD2 /* NSDataAES256.m in Sources */, - 994E29721783919400EAACD2 /* Reachability.m in Sources */, + 993EFA181847C37A0061C758 /* NSDataAES256.m in Sources */, + 993EFA171847C2E30061C758 /* GameCenterManager.m in Sources */, + 993EFA191847C37E0061C758 /* Reachability.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -545,6 +506,7 @@ 659699F81515718800724EBE /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CLANG_ENABLE_OBJC_ARC = YES; @@ -554,10 +516,11 @@ GCC_PREFIX_HEADER = "GameCenterManager/GameCenterManager-Prefix.pch"; GCC_THUMB_SUPPORT = NO; INFOPLIST_FILE = "GameCenterManager/GameCenterManager-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1.1; + ONLY_ACTIVE_ARCH = NO; PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE = "0267AEAF-9C47-4D68-B69E-87B0B4DA938D"; - "PROVISIONING_PROFILE[sdk=iphoneos*]" = "0267AEAF-9C47-4D68-B69E-87B0B4DA938D"; + PROVISIONING_PROFILE = ""; + "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; TARGETED_DEVICE_FAMILY = 1; WRAPPER_EXTENSION = app; }; @@ -566,6 +529,7 @@ 659699F91515718800724EBE /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CLANG_ENABLE_OBJC_ARC = YES; @@ -575,10 +539,10 @@ GCC_PREFIX_HEADER = "GameCenterManager/GameCenterManager-Prefix.pch"; GCC_THUMB_SUPPORT = NO; INFOPLIST_FILE = "GameCenterManager/GameCenterManager-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1.1; PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE = "0267AEAF-9C47-4D68-B69E-87B0B4DA938D"; - "PROVISIONING_PROFILE[sdk=iphoneos*]" = "0267AEAF-9C47-4D68-B69E-87B0B4DA938D"; + PROVISIONING_PROFILE = ""; + "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; TARGETED_DEVICE_FAMILY = 1; WRAPPER_EXTENSION = app; }; diff --git a/GameCenterManager.xcodeproj/project.xcworkspace/xcuserdata/Spencers.xcuserdatad/UserInterfaceState.xcuserstate b/GameCenterManager.xcodeproj/project.xcworkspace/xcuserdata/Spencers.xcuserdatad/UserInterfaceState.xcuserstate index 42980c3..f594e62 100755 Binary files a/GameCenterManager.xcodeproj/project.xcworkspace/xcuserdata/Spencers.xcuserdatad/UserInterfaceState.xcuserstate and b/GameCenterManager.xcodeproj/project.xcworkspace/xcuserdata/Spencers.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/GameCenterManager/AppDelegate.m b/GameCenterManager/AppDelegate.m index dc445c7..061b807 100755 --- a/GameCenterManager/AppDelegate.m +++ b/GameCenterManager/AppDelegate.m @@ -13,46 +13,37 @@ @implementation AppDelegate @synthesize window = _window; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - //Override point for customization after application launch. + // Override point for customization after application launch. - //Setup GameCenter + // Setup GameCenter [[GameCenterManager sharedManager] initGameCenter]; return YES; } - (void)applicationWillResignActive:(UIApplication *)application { - /* - Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. - */ + /* Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. */ } - (void)applicationDidEnterBackground:(UIApplication *)application { - /* - Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + /* Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. */ } - (void)applicationWillEnterForeground:(UIApplication *)application { - /* - Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. - */ + /* Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. */ } - (void)applicationDidBecomeActive:(UIApplication *)application { - /* - Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - */ + /* Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. */ } - (void)applicationWillTerminate:(UIApplication *)application { - /* - Called when the application is about to terminate. + /* Called when the application is about to terminate. Save data if appropriate. - See also applicationDidEnterBackground:. - */ + See also applicationDidEnterBackground:. */ } @end diff --git a/GameCenterManager/GC Manager/GameCenterManager.h b/GameCenterManager/GC Manager/GameCenterManager.h deleted file mode 100755 index 25f5cc1..0000000 --- a/GameCenterManager/GC Manager/GameCenterManager.h +++ /dev/null @@ -1,155 +0,0 @@ -// -// 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] -#define __GK_USES_LEADERBOARD_ID [[GKLeaderboard alloc] respondsToSelector:@selector(leaderboardIdentifier)] == YES -#define __GK_USES_IDENTIFIER ([[GKLeaderboard alloc] respondsToSelector:@selector(identifier)]) - -#import -#import -#import "Reachability.h" -#import "NSDataAES256.h" - -typedef enum GameCenterSortOrder { - GameCenterSortOrderHighToLow, - GameCenterSortOrderLowToHigh -} GameCenterSortOrder; - -enum { - GCMErrorUnknown = 1, - GCMErrorNotAvailable = 2, - GCMErrorFeatureNotAvailable = 3, - GCMErrorInternetNotAvailable = 4, - GCMErrorAchievementDataMissing = 5 -}; -typedef NSInteger GCMErrorCode; - - -@protocol GameCenterManagerDelegate; -@interface GameCenterManager : NSObject { - NSMutableArray *_leaderboards; - UIBackgroundTaskIdentifier backgroundProcess; -} - -// Sets up the Delegate -@property (nonatomic, weak) id 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. -- (void)saveAndReportScore:(int)score leaderboard:(NSString *)identifier sortOrder:(GameCenterSortOrder)order; - -/// Saves achievement locally and reports it to Game Center. If error occurs, achievement is saved to be submitted later. -- (void)saveAndReportAchievement:(NSString *)identifier percentComplete:(double)percentComplete shouldDisplayNotification:(BOOL)displayNotification; - - - -/// 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; - - - -/// Resets local player's achievements -- (void)resetAchievementsWithCompletion:(void (^)(NSError *error))handler; - - - -/// 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; - -/// 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; - - - -/// 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 -@protocol GameCenterManagerDelegate - -@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; - -@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; - -- (void)gameCenterManager:(GameCenterManager *)manager reportedScore:(NSDictionary *)scoreInformation; -- (void)gameCenterManager:(GameCenterManager *)manager reportedAchievement:(NSDictionary *)achievementInformation; -- (void)gameCenterManager:(GameCenterManager *)manager savedScore:(GKScore *)score; -- (void)gameCenterManager:(GameCenterManager *)manager savedAchievement:(NSDictionary *)achievementInformation; - -- (void)gameCenterManager:(GameCenterManager *)manager resetAchievements:(NSError *)error __deprecated; -@end - - - diff --git a/GameCenterManager/GC Manager/GameCenterManager.m b/GameCenterManager/GC Manager/GameCenterManager.m deleted file mode 100755 index d2f9c4f..0000000 --- a/GameCenterManager/GC Manager/GameCenterManager.m +++ /dev/null @@ -1,809 +0,0 @@ -// -// GameCenterManager.m -// -// Created by Nihal Ahmed on 12-03-16. Updated by iRare Media on 5-27-13. -// Copyright (c) 2012 NABZ Software. All rights reserved. -// - -#import "GameCenterManager.h" - - -//------------------------------------------------------------------------------------------------------------// -//------- GameCenter Manager Singleton -----------------------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark GameCenter Manager - -@implementation GameCenterManager -@synthesize isGameCenterAvailable, delegate; - -static GameCenterManager *sharedManager = nil; - -+ (GameCenterManager *)sharedManager { - if (sharedManager == nil) { - sharedManager = [[super allocWithZone:NULL] init]; - NSFileManager *fileManager = [NSFileManager defaultManager]; - if (![fileManager fileExistsAtPath:kGameCenterManagerDataPath]) { - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:dict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - } - - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - if (gameCenterManagerData == nil) { - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:dict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - - return sharedManager; -} - -+ (id)allocWithZone:(NSZone *)zone { - return [self sharedManager]; -} - -- (id)copyWithZone:(NSZone *)zone { - return self; -} - -//------------------------------------------------------------------------------------------------------------// -//------- GameCenter Manager Setup ---------------------------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark - GameCenter Manager Setup - -- (void)initGameCenter { - BOOL gameCenterAvailable = [self checkGameCenterAvailability]; - if (gameCenterAvailable) { - //Set GameCenter as available - [[GameCenterManager sharedManager] setIsGameCenterAvailable:YES]; - - if (![[NSUserDefaults standardUserDefaults] boolForKey:[@"scoresSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]] || - ![[NSUserDefaults standardUserDefaults] boolForKey:[@"achievementsSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]]) { - [[GameCenterManager sharedManager] syncGameCenter]; - } else { - [[GameCenterManager sharedManager] reportSavedScoresAndAchievements]; - } - - } else { - [[GameCenterManager sharedManager] setIsGameCenterAvailable:NO]; - } -} - -- (BOOL)checkGameCenterAvailability { - // First, check if the the GameKit Framework exists on the device. Return NO if it does not. - BOOL localPlayerClassAvailable = (NSClassFromString(@"GKLocalPlayer")) != nil; - NSString *reqSysVer = @"4.1"; - NSString *currSysVer = [[UIDevice currentDevice] systemVersion]; - BOOL osVersionSupported = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending); - BOOL isGameCenterAPIAvailable = (localPlayerClassAvailable && osVersionSupported); - - if (!isGameCenterAPIAvailable) { - NSDictionary *errorDictionary = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"GameKit Framework not available on this device. GameKit is only available on devices with iOS 4.1 or higher. Some devices running iOS 4.1 may not have GameCenter enabled.", @"GameCenter Unavailable", nil] forKeys:[NSArray arrayWithObjects:@"message", @"title", nil]]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:availabilityChanged:)]) - [[self delegate] gameCenterManager:self availabilityChanged:errorDictionary]; - }); - - return NO; - - } else { - // The GameKit Framework is available. Now check if an internet connection can be established - BOOL internetAvailable = [self isInternetAvailable]; - if (!internetAvailable) { - NSDictionary *errorDictionary = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Cannot connect to the internet. Connect to the internet to establish a connection with GameCenter. Achievements and scores will still be saved locally and then uploaded later.", @"Internet Unavailable", nil] forKeys:[NSArray arrayWithObjects:@"message", @"title", nil]]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:availabilityChanged:)]) - [[self delegate] gameCenterManager:self availabilityChanged:errorDictionary]; - }); - - return NO; - - } else { - // The internet is available and the current device is connected. Now check if the player is authenticated - GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; - localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) { - if (viewController != nil) { - NSDictionary *errorDictionary = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Player is not yet signed into GameCenter. Please prompt the player using the authenticateUser delegate method.", @"No Player", nil] forKeys:[NSArray arrayWithObjects:@"message", @"title", nil]]; - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:availabilityChanged:)]) - [[self delegate] gameCenterManager:self availabilityChanged:errorDictionary]; - - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:authenticateUser:)]) { - [[self delegate] gameCenterManager:self authenticateUser:viewController]; - } else { - NSLog(@"[ERROR] %@ Fails to Respond to the required delegate method gameCenterManager:authenticateUser:. This delegate method must be properly implemented to use GC Manager", [self delegate]); - } - }); - } else if (!error) { - // Authentication handler completed successfully. Re-check availability - [self checkGameCenterAvailability]; - } - }; - - if (![[GKLocalPlayer localPlayer] isAuthenticated]) { - NSDictionary *errorDictionary = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Player is not signed into GameCenter, has declined to sign into GameCenter, or GameKit had an issue validating this game / app.", @"Player not Authenticated", nil] forKeys:[NSArray arrayWithObjects:@"message", @"title", nil]]; - - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:availabilityChanged:)]) - [[self delegate] gameCenterManager:self availabilityChanged:errorDictionary]; - - return NO; - - } else { - // The current player is logged into GameCenter - NSDictionary *successDictionary = [NSDictionary dictionaryWithObject:@"GameCenter Available" forKey:@"status"]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:availabilityChanged:)]) - [[self delegate] gameCenterManager:self availabilityChanged:successDictionary]; - }); - - self.isGameCenterAvailable = YES; - - return YES; - } - } - } -} - -// Check for internet with Reachability -- (BOOL)isInternetAvailable { - Reachability *reachability = [Reachability reachabilityForInternetConnection]; - NetworkStatus internetStatus = [reachability currentReachabilityStatus]; - - if (internetStatus == NotReachable) { - NSError *error = [NSError errorWithDomain:[NSString stringWithFormat:@"Internet unavailable - could not connect to the internet. Connect to WiFi or a Cellular Network to upload data to GameCenter."] code:GCMErrorInternetNotAvailable userInfo:nil]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - - return NO; - } else { - return YES; - } -} - -//------------------------------------------------------------------------------------------------------------// -//------- GameCenter Syncing ---------------------------------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark - GameCenter Syncing - -- (void)syncGameCenter { - // Begin Syncing with GameCenter - - // Ensure the task isn't interrupted even if the user exits the app - backgroundProcess = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ - //End the Background Process - [[UIApplication sharedApplication] endBackgroundTask:backgroundProcess]; - backgroundProcess = UIBackgroundTaskInvalid; - }]; - - // Move the process to the background thread to avoid clogging up the UI - dispatch_queue_t syncGameCenterOnBackgroundThread = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul); - dispatch_async(syncGameCenterOnBackgroundThread, ^{ - - // Check if GameCenter is available - if ([[GameCenterManager sharedManager] checkGameCenterAvailability] == YES) { - // Check if Leaderboard Scores are synced - if (![[NSUserDefaults standardUserDefaults] boolForKey:[@"scoresSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]]) { - if (_leaderboards == nil) { - [GKLeaderboard loadLeaderboardsWithCompletionHandler:^(NSArray *leaderboards, NSError *error) { - if (error == nil) { - _leaderboards = [[NSMutableArray alloc] initWithArray:leaderboards]; - [[GameCenterManager sharedManager] syncGameCenter]; - } else { - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - } - }]; - return; - } - - - if (_leaderboards.count > 0) { - GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] initWithPlayerIDs:[NSArray arrayWithObject:[[GameCenterManager sharedManager] localPlayerId]]]; - - if ([[GKLeaderboard alloc] respondsToSelector:@selector(identifier)]) { - [leaderboardRequest setIdentifier:[(GKLeaderboard *)[_leaderboards objectAtIndex:0] identifier]]; - } else { - [leaderboardRequest setCategory:[(GKLeaderboard *)[_leaderboards objectAtIndex:0] category]]; - } - - [leaderboardRequest loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) { - if (error == nil) { - if (scores.count > 0) { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict == nil) { - playerDict = [NSMutableDictionary dictionary]; - } - - float savedHighScoreValue = 0; - NSNumber *savedHighScore = [playerDict objectForKey:leaderboardRequest.localPlayerScore.category]; - - if (savedHighScore != nil) { - savedHighScoreValue = [savedHighScore intValue]; - } - - [playerDict setObject:[NSNumber numberWithInt:MAX(leaderboardRequest.localPlayerScore.value, savedHighScoreValue)] forKey:leaderboardRequest.localPlayerScore.category]; - [plistDict setObject:playerDict forKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - - // Seeing an NSRangeException for an empty array when trying to remove the object - // Despite the check above in this scope that leaderboards count is > 0 - if (_leaderboards.count > 0) { - [_leaderboards removeObjectAtIndex:0]; - } - - [[GameCenterManager sharedManager] syncGameCenter]; - } else { - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - } - }]; - } else { - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:[@"scoresSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]]; - [[GameCenterManager sharedManager] syncGameCenter]; - } - - - // Check if Achievements are synced - } else if (![[NSUserDefaults standardUserDefaults] boolForKey:[@"achievementsSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]]) { - [GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) { - if (error == nil) { - NSLog(@"Number of Achievements: %@", achievements); - if (achievements.count > 0) { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict == nil) { - playerDict = [NSMutableDictionary dictionary]; - } - - for (GKAchievement *achievement in achievements) { - [playerDict setObject:[NSNumber numberWithDouble:achievement.percentComplete] forKey:achievement.identifier]; - } - - [plistDict setObject:playerDict forKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - - } - - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:[@"achievementsSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]]; - [[GameCenterManager sharedManager] syncGameCenter]; - } else { - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - } - }]; - } - } else { - NSError *error = [NSError errorWithDomain:[NSString stringWithFormat:@"GameCenter unavailable."] code:GCMErrorNotAvailable userInfo:nil]; - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - } - }); - - // End the Background Process - [[UIApplication sharedApplication] endBackgroundTask:backgroundProcess]; - backgroundProcess = UIBackgroundTaskInvalid; -} - -// Report data when the internet is available again -- (void)reportSavedScoresAndAchievements { - if ([[GameCenterManager sharedManager] isInternetAvailable]) { - GKScore *gkScore = nil; - - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableArray *savedScores = [plistDict objectForKey:@"SavedScores"]; - - if (savedScores != nil) { - if (savedScores.count > 0) { - gkScore = [NSKeyedUnarchiver unarchiveObjectWithData:[savedScores objectAtIndex:0]]; - - [savedScores removeObjectAtIndex:0]; - [plistDict setObject:savedScores forKey:@"SavedScores"]; - - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - } - - if (gkScore != nil) { - [gkScore reportScoreWithCompletionHandler:^(NSError *error) { - if (error == nil) { - [[GameCenterManager sharedManager] reportSavedScoresAndAchievements]; - } else { - [[GameCenterManager sharedManager] saveScoreToReportLater:gkScore]; - } - }]; - } else { - if ([GKLocalPlayer localPlayer].authenticated) { - NSString *identifier = nil; - double percentComplete = 0; - - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict != nil) { - NSMutableDictionary *savedAchievements = [playerDict objectForKey:@"SavedAchievements"]; - if (savedAchievements != nil) { - if (savedAchievements.count > 0) { - identifier = [[savedAchievements allKeys] objectAtIndex:0]; - percentComplete = [[savedAchievements objectForKey:identifier] doubleValue]; - - [savedAchievements removeObjectForKey:identifier]; - [playerDict setObject:savedAchievements forKey:@"SavedAchievements"]; - [plistDict setObject:playerDict forKey:[[GameCenterManager sharedManager] localPlayerId]]; - - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - } - } - - if (identifier != nil) { - GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier:identifier]; - achievement.percentComplete = percentComplete; - [achievement reportAchievementWithCompletionHandler:^(NSError *error) { - if (error == nil) { - [[GameCenterManager sharedManager] reportSavedScoresAndAchievements]; - } else { - [[GameCenterManager sharedManager] saveAchievementToReportLater:achievement.identifier percentComplete:achievement.percentComplete]; - } - }]; - - } - } - } - } -} - - -//------------------------------------------------------------------------------------------------------------// -//------- Score and Achievement Reporting --------------------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark - Score and Achievement Reporting - -// Save score and report it to GameCenter -- (void)saveAndReportScore:(int)score leaderboard:(NSString *)identifier sortOrder:(GameCenterSortOrder)order { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict == nil) { - playerDict = [NSMutableDictionary dictionary]; - } - - NSNumber *savedHighScore = [playerDict objectForKey:identifier]; - if (savedHighScore == nil) { - savedHighScore = [NSNumber numberWithInt:0]; - } - - int savedHighScoreValue = [savedHighScore intValue]; - - // Determine if the new score is better than the old score - BOOL isScoreBetter = NO; - switch (order) { - case GameCenterSortOrderLowToHigh: // A lower score is better - if (score < savedHighScoreValue) { - isScoreBetter = YES; - } - break; - default: - if (score > savedHighScoreValue) { // A higher score is better - isScoreBetter = YES; - } - break; - } - - if (isScoreBetter) { - [playerDict setObject:[NSNumber numberWithInt:score] forKey:identifier]; - [plistDict setObject:playerDict forKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - - if ([[GameCenterManager sharedManager] checkGameCenterAvailability] == YES) { - GKScore *gkScore = [[GKScore alloc] initWithCategory:identifier]; - gkScore.value = score; - - [gkScore reportScoreWithCompletionHandler:^(NSError *error) { - NSDictionary *dict = nil; - - if (error == nil) { - dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:gkScore, nil] forKeys:[NSArray arrayWithObjects:@"score", nil]]; - } else { - dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:error.localizedDescription, gkScore, nil] forKeys:[NSArray arrayWithObjects:@"error", @"score", nil]]; - [[GameCenterManager sharedManager] saveScoreToReportLater:gkScore]; - } - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:reportedScore:)]) - [[self delegate] gameCenterManager:self reportedScore:dict]; - }); - }]; - - } else { - GKScore *gkScore = [[GKScore alloc] initWithCategory:identifier]; - [[GameCenterManager sharedManager] saveScoreToReportLater:gkScore]; - } -} - -// Save achievement and report it to GameCenter -- (void)saveAndReportAchievement:(NSString *)identifier percentComplete:(double)percentComplete shouldDisplayNotification:(BOOL)displayNotification { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict == nil) - playerDict = [NSMutableDictionary dictionary]; - - NSNumber *savedPercentComplete = [playerDict objectForKey:identifier]; - if (savedPercentComplete == nil) - savedPercentComplete = [NSNumber numberWithDouble:0]; - - double savedPercentCompleteValue = [savedPercentComplete doubleValue]; - if (percentComplete > savedPercentCompleteValue) { - [playerDict setObject:[NSNumber numberWithDouble:percentComplete] forKey:identifier]; - [plistDict setObject:playerDict forKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - } - - if ([[GameCenterManager sharedManager] checkGameCenterAvailability] == YES) { - GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier:identifier]; - achievement.percentComplete = percentComplete; - if (displayNotification == YES) { - achievement.showsCompletionBanner = YES; - } else { - achievement.showsCompletionBanner = NO; - } - - [achievement reportAchievementWithCompletionHandler:^(NSError *error) { - NSDictionary *dict = nil; - - if (error == nil) { - dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:achievement, nil] forKeys:[NSArray arrayWithObjects:@"achievement", nil]]; - } else { - if (achievement) { - dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:error.localizedDescription, achievement, nil] forKeys:[NSArray arrayWithObjects:@"error", @"achievement", nil]]; - } - - [[GameCenterManager sharedManager] saveAchievementToReportLater:identifier percentComplete:percentComplete]; - } - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:reportedAchievement:)]) - [[self delegate] gameCenterManager:self reportedAchievement:dict]; - }); - - }]; - - } else { - [[GameCenterManager sharedManager] saveAchievementToReportLater:identifier percentComplete:percentComplete]; - } -} - -// Save score to report later -- (void)saveScoreToReportLater:(GKScore *)score { - NSData *scoreData = [NSKeyedArchiver archivedDataWithRootObject:score]; - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableArray *savedScores = [plistDict objectForKey:@"SavedScores"]; - - if (savedScores != nil) { - [savedScores addObject:scoreData]; - } else { - savedScores = [NSMutableArray arrayWithObject:scoreData]; - } - - [plistDict setObject:savedScores forKey:@"SavedScores"]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:savedScore:)]) - [[self delegate] gameCenterManager:self savedScore:score]; - }); -} - -- (void)saveAchievementToReportLater:(NSString *)identifier percentComplete:(double)percentComplete { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict != nil) { - NSMutableDictionary *savedAchievements = [playerDict objectForKey:@"SavedAchievements"]; - if (savedAchievements != nil) { - double savedPercentCompleteValue = 0; - NSNumber *savedPercentComplete = [savedAchievements objectForKey:identifier]; - - if (savedPercentComplete != nil) { - savedPercentCompleteValue = [savedPercentComplete doubleValue]; - } - - // Compare the saved percent and the percent that was just submitted, if the submitted percent is greater save it - if (percentComplete > savedPercentCompleteValue) { - savedPercentComplete = [NSNumber numberWithDouble:percentComplete]; - [savedAchievements setObject:savedPercentComplete forKey:identifier]; - } - } else { - savedAchievements = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithDouble:percentComplete], identifier, nil]; - [playerDict setObject:savedAchievements forKey:@"SavedAchievements"]; - } - } else { - NSMutableDictionary *savedAchievements = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithDouble:percentComplete], identifier, nil]; - playerDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:savedAchievements, @"SavedAchievements", nil]; - } - - [plistDict setObject:playerDict forKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - - GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier:identifier]; - NSNumber *percentNumber = [NSNumber numberWithDouble:percentComplete]; - - if (percentNumber && achievement) { - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:savedAchievement:)]) - [[self delegate] gameCenterManager:self savedAchievement:[NSDictionary dictionaryWithObjects:@[achievement, percentNumber] forKeys:@[@"achievement", @"percent complete"]]]; - }); - } else { - NSError *error = [NSError errorWithDomain:[NSString stringWithFormat:@"Could not save achievement because necessary data is missing. GameCenter needs an Achievement ID and Percent Completed to save the achievement. You provided the following data:\nAchievement: %@\nPercent Completed:%@", achievement, percentNumber] - code:GCMErrorAchievementDataMissing userInfo:nil]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - } -} - -//------------------------------------------------------------------------------------------------------------// -//------- Score, Achievement, and Challenge Retrieval --------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark - Score, Achievement, and Challenge Retrieval - -- (int)highScoreForLeaderboard:(NSString *)identifier { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict != nil) { - NSNumber *savedHighScore = [playerDict objectForKey:identifier]; - if (savedHighScore != nil) { - return [savedHighScore intValue]; - } else { - return 0; - } - } else { - return 0; - } -} - -// Get leaderboard high scores -- (NSDictionary *)highScoreForLeaderboards:(NSArray *)identifiers { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSMutableDictionary *highScores = [[NSMutableDictionary alloc] initWithCapacity:identifiers.count]; - - for (NSString *identifier in identifiers) { - if (playerDict != nil) { - NSNumber *savedHighScore = [playerDict objectForKey:identifier]; - - if (savedHighScore != nil) { - [highScores setObject:[NSNumber numberWithInt:[savedHighScore intValue]] forKey:identifier]; - continue; - } - } - - [highScores setObject:[NSNumber numberWithInt:0] forKey:identifier]; - } - - NSDictionary *highScoreDict = [NSDictionary dictionaryWithDictionary:highScores]; - - return highScoreDict; -} - -// Get achievement progress -- (double)progressForAchievement:(NSString *)identifier { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict != nil) { - NSNumber *savedPercentComplete = [playerDict objectForKey:identifier]; - - if (savedPercentComplete != nil) { - return [savedPercentComplete doubleValue]; - } - } - return 0; -} - -// Returns local player's percent completed for multiple achievements. -- (NSDictionary *)progressForAchievements:(NSArray *)identifiers { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSMutableDictionary *percent = [[NSMutableDictionary alloc] initWithCapacity:identifiers.count]; - - for (NSString *identifier in identifiers) { - if (playerDict != nil) { - NSNumber *savedPercentComplete = [playerDict objectForKey:identifier]; - - if (savedPercentComplete != nil) { - [percent setObject:[NSNumber numberWithDouble:[savedPercentComplete doubleValue]] forKey:identifier]; - continue; - } - } - - [percent setObject:[NSNumber numberWithDouble:0] forKey:identifier]; - } - - NSDictionary *percentDict = [NSDictionary dictionaryWithDictionary:percent]; - - return percentDict; -} - -// Returns local player's challenges for this game -- (void)getChallengesWithCompletion:(void (^)(NSArray *challenges, NSError *error))handler { - if ([[GameCenterManager sharedManager] checkGameCenterAvailability] == YES) { - BOOL isGameCenterChallengeAPIAvailable = (NSClassFromString(@"GKChallenge")) != nil; - - if (isGameCenterChallengeAPIAvailable == YES) { - [GKChallenge loadReceivedChallengesWithCompletionHandler:^(NSArray *challenges, NSError *error) { - if (error == nil) { - handler(challenges, nil); - } else { - handler(nil, error); - } - }]; - } else { - NSError *error = [NSError errorWithDomain:[NSString stringWithFormat:@"GKChallenge Class is not available. GKChallenge is only available on iOS 6.0 and higher. Current iOS version: %@", [[UIDevice currentDevice] systemVersion]] code:GCMErrorFeatureNotAvailable userInfo:nil]; - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - } - } else { - NSError *error = [NSError errorWithDomain:[NSString stringWithFormat:@"GameCenter Unavailable"] code:GCMErrorNotAvailable userInfo:nil]; - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - } -} - -//------------------------------------------------------------------------------------------------------------// -//------- Resetting Data -------------------------------------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark - Resetting Data - -// Reset all achievements and progress -- (void)resetAchievementsWithCompletion:(void (^)(NSError *))handler { - if ([[GameCenterManager sharedManager] isGameCenterAvailable]) { - [GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) { - if (error == nil) { - NSData *gameCenterManagerData = [[NSData dataWithContentsOfFile:kGameCenterManagerDataPath] decryptedWithKey:kGameCenterManagerKey]; - NSMutableDictionary *plistDict = [NSKeyedUnarchiver unarchiveObjectWithData:gameCenterManagerData]; - NSMutableDictionary *playerDict = [plistDict objectForKey:[[GameCenterManager sharedManager] localPlayerId]]; - - if (playerDict == nil) { - playerDict = [NSMutableDictionary dictionary]; - } - - for (GKAchievement *achievement in achievements) { - [playerDict removeObjectForKey:achievement.identifier]; - } - - [plistDict setObject:playerDict forKey:[[GameCenterManager sharedManager] localPlayerId]]; - NSData *saveData = [[NSKeyedArchiver archivedDataWithRootObject:plistDict] encryptedWithKey:kGameCenterManagerKey]; - [saveData writeToFile:kGameCenterManagerDataPath atomically:YES]; - - [GKAchievement resetAchievementsWithCompletionHandler:^(NSError *error) { - if (error == nil) { - [[NSUserDefaults standardUserDefaults] setBool:NO forKey:[@"achievementsSynced" stringByAppendingString:[[GameCenterManager sharedManager] localPlayerId]]]; - [[NSUserDefaults standardUserDefaults] synchronize]; - - [self syncGameCenter]; - - dispatch_async(dispatch_get_main_queue(), ^{ - handler(nil); - }); - } else { - dispatch_async(dispatch_get_main_queue(), ^{ - handler(error); - }); - } - }]; - } else { - dispatch_async(dispatch_get_main_queue(), ^{ - handler(error); - }); - } - }]; - } -} - -//------------------------------------------------------------------------------------------------------------// -//------- Player Data ----------------------------------------------------------------------------------------// -//------------------------------------------------------------------------------------------------------------// -#pragma mark - Player Data - -// Checks if player is authenticated and gets his / her ID -- (NSString *)localPlayerId { - if ([[GameCenterManager sharedManager] isGameCenterAvailable]) { - if ([GKLocalPlayer localPlayer].authenticated) { - return [GKLocalPlayer localPlayer].playerID; - } - } - return @"unknownPlayer"; -} - -// Returns the local player's display name -- (NSString *)localPlayerDisplayName { - if ([[GameCenterManager sharedManager] isGameCenterAvailable] && [GKLocalPlayer localPlayer].authenticated) { - if ([[GKLocalPlayer localPlayer] respondsToSelector:@selector(displayName)]) { - return [GKLocalPlayer localPlayer].displayName; - } else { - return [GKLocalPlayer localPlayer].alias; - } - } - - return @"unknownPlayer"; -} - -// Checks if player is authenticated and gets his / her ID -- (GKLocalPlayer *)localPlayerData { - if ([[GameCenterManager sharedManager] isGameCenterAvailable] && [GKLocalPlayer localPlayer].authenticated) { - return [GKLocalPlayer localPlayer]; - } else { - return nil; - } -} - -- (void)localPlayerPhoto:(void (^)(UIImage *playerPhoto))handler { - if ([[GameCenterManager sharedManager] isGameCenterAvailable]) { - if ([GKPlayer respondsToSelector:@selector(loadPhotoForSize:withCompletionHandler:)]) { - [[self localPlayerData] loadPhotoForSize:GKPhotoSizeNormal withCompletionHandler:^(UIImage *photo, NSError *error) { - handler(photo); - if (error) { - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - }); - } - }]; - } else { - NSError *error = [NSError errorWithDomain:[NSString stringWithFormat:@"loadPhotoForSize:withCompletionHandler: method is not available. loadPhotoForSize:withCompletionHandler: is only available on iOS 5.0 and higher. Current iOS version: %@", [[UIDevice currentDevice] systemVersion]] code:GCMErrorFeatureNotAvailable userInfo:nil]; - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - } - } else { - NSError *error = [NSError errorWithDomain:[NSString stringWithFormat:@"GameCenter Unavailable"] code:GCMErrorNotAvailable userInfo:nil]; - if ([[self delegate] respondsToSelector:@selector(gameCenterManager:error:)]) - [[self delegate] gameCenterManager:self error:error]; - } -} - -@end \ No newline at end of file diff --git a/GameCenterManager/GC Manager/NSDataAES256.h b/GameCenterManager/GC Manager/NSDataAES256.h deleted file mode 100755 index 539abaf..0000000 --- a/GameCenterManager/GC Manager/NSDataAES256.h +++ /dev/null @@ -1,12 +0,0 @@ -// -// NSDataAES256.h -// - -#import - -@interface NSData (AES256) - -- (NSData*) encryptedWithKey:(NSData*) key; -- (NSData*) decryptedWithKey:(NSData*) key; - -@end diff --git a/GameCenterManager/GC Manager/NSDataAES256.m b/GameCenterManager/GC Manager/NSDataAES256.m deleted file mode 100755 index 9282da6..0000000 --- a/GameCenterManager/GC Manager/NSDataAES256.m +++ /dev/null @@ -1,72 +0,0 @@ -// -// NSDataAES256.m -// - -#import "NSDataAES256.h" -#import - -// Key size is 32 bytes for AES256 -#define kKeySize kCCKeySizeAES256 - -@implementation NSData (AES256) - -- (NSData*)makeCryptedVersionWithKeyData:(const void*) keyData ofLength:(int) keyLength decrypt:(bool) decrypt { - // Copy the key data, padding with zeroes if needed - char key[kKeySize]; - bzero(key, sizeof(key)); - memcpy(key, keyData, keyLength > kKeySize ? kKeySize : keyLength); - - size_t bufferSize = [self length] + kCCBlockSizeAES128; - void* buffer = malloc(bufferSize); - - size_t dataUsed; - - CCCryptorStatus status = CCCrypt(decrypt ? kCCDecrypt : kCCEncrypt, - kCCAlgorithmAES128, - kCCOptionPKCS7Padding | kCCOptionECBMode, - key, kKeySize, - NULL, - [self bytes], [self length], - buffer, bufferSize, - &dataUsed); - - switch(status) { - case kCCSuccess: - return [NSData dataWithBytesNoCopy:buffer length:dataUsed]; - case kCCParamError: - NSLog(@"Error: NSDataAES256: Could not %s data: Param error", decrypt ? "decrypt" : "encrypt"); - break; - case kCCBufferTooSmall: - NSLog(@"Error: NSDataAES256: Could not %s data: Buffer too small", decrypt ? "decrypt" : "encrypt"); - break; - case kCCMemoryFailure: - NSLog(@"Error: NSDataAES256: Could not %s data: Memory failure", decrypt ? "decrypt" : "encrypt"); - break; - case kCCAlignmentError: - NSLog(@"Error: NSDataAES256: Could not %s data: Alignment error", decrypt ? "decrypt" : "encrypt"); - break; - case kCCDecodeError: - NSLog(@"Error: NSDataAES256: Could not %s data: Decode error", decrypt ? "decrypt" : "encrypt"); - break; - case kCCUnimplemented: - NSLog(@"Error: NSDataAES256: Could not %s data: Unimplemented", decrypt ? "decrypt" : "encrypt"); - break; - default: - NSLog(@"Error: NSDataAES256: Could not %s data: Unknown error", decrypt ? "decrypt" : "encrypt"); - } - - free(buffer); - return nil; -} - -- (NSData*) encryptedWithKey:(NSData*) key -{ - return [self makeCryptedVersionWithKeyData:[key bytes] ofLength:[key length] decrypt:NO]; -} - -- (NSData*) decryptedWithKey:(NSData*) key -{ - return [self makeCryptedVersionWithKeyData:[key bytes] ofLength:[key length] decrypt:YES]; -} - -@end diff --git a/GameCenterManager/GC Manager/Reachability.h b/GameCenterManager/GC Manager/Reachability.h deleted file mode 100755 index 9febed8..0000000 --- a/GameCenterManager/GC Manager/Reachability.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - Copyright (c) 2011, Tony Million. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ - -#import -#import - -#import -#import -#import -#import -#import -#import - -/** - * Does ARC support support GCD objects? - * It does if the minimum deployment target is iOS 6+ or Mac OS X 8+ - * - * @see http://opensource.apple.com/source/libdispatch/libdispatch-228.18/os/object.h - **/ -#if OS_OBJECT_USE_OBJC -#define NEEDS_DISPATCH_RETAIN_RELEASE 0 -#else -#define NEEDS_DISPATCH_RETAIN_RELEASE 1 -#endif - - -extern NSString *const kReachabilityChangedNotification; - -typedef enum -{ - // Apple NetworkStatus Compatible Names. - NotReachable = 0, - ReachableViaWiFi = 2, - ReachableViaWWAN = 1 -} NetworkStatus; - -@class Reachability; - -typedef void (^NetworkReachable)(Reachability * reachability); -typedef void (^NetworkUnreachable)(Reachability * reachability); - -@interface Reachability : NSObject - -@property (nonatomic, copy) NetworkReachable reachableBlock; -@property (nonatomic, copy) NetworkUnreachable unreachableBlock; - - -@property (nonatomic, assign) BOOL reachableOnWWAN; - -+(Reachability*)reachabilityWithHostname:(NSString*)hostname; -+(Reachability*)reachabilityForInternetConnection; -+(Reachability*)reachabilityWithAddress:(const struct sockaddr_in*)hostAddress; -+(Reachability*)reachabilityForLocalWiFi; - --(Reachability *)initWithReachabilityRef:(SCNetworkReachabilityRef)ref; - --(BOOL)startNotifier; --(void)stopNotifier; - --(BOOL)isReachable; --(BOOL)isReachableViaWWAN; --(BOOL)isReachableViaWiFi; - -// WWAN may be available, but not active until a connection has been established. -// WiFi may require a connection for VPN on Demand. --(BOOL)isConnectionRequired; // Identical DDG variant. --(BOOL)connectionRequired; // Apple's routine. -// Dynamic, on demand connection? --(BOOL)isConnectionOnDemand; -// Is user intervention required? --(BOOL)isInterventionRequired; - --(NetworkStatus)currentReachabilityStatus; --(SCNetworkReachabilityFlags)reachabilityFlags; --(NSString*)currentReachabilityString; --(NSString*)currentReachabilityFlags; - -@end diff --git a/GameCenterManager/GC Manager/Reachability.m b/GameCenterManager/GC Manager/Reachability.m deleted file mode 100755 index 348b33e..0000000 --- a/GameCenterManager/GC Manager/Reachability.m +++ /dev/null @@ -1,519 +0,0 @@ -/* - Copyright (c) 2011, Tony Million. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ - -#import "Reachability.h" - - -NSString *const kReachabilityChangedNotification = @"kReachabilityChangedNotification"; - -@interface Reachability () - -@property (nonatomic, assign) SCNetworkReachabilityRef reachabilityRef; - - -#if NEEDS_DISPATCH_RETAIN_RELEASE -@property (nonatomic, assign) dispatch_queue_t reachabilitySerialQueue; -#else -@property (nonatomic, strong) dispatch_queue_t reachabilitySerialQueue; -#endif - - -@property (nonatomic, strong) id reachabilityObject; - --(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags; --(BOOL)isReachableWithFlags:(SCNetworkReachabilityFlags)flags; - -@end - -static NSString *reachabilityFlags(SCNetworkReachabilityFlags flags) -{ - return [NSString stringWithFormat:@"%c%c %c%c%c%c%c%c%c", -#if TARGET_OS_IPHONE - (flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-', -#else - 'X', -#endif - (flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-', - (flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-', - (flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-', - (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-', - (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-', - (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-', - (flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-', - (flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-']; -} - -//Start listening for reachability notifications on the current run loop -static void TMReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) -{ -#pragma unused (target) -#if __has_feature(objc_arc) - Reachability *reachability = ((__bridge Reachability*)info); -#else - Reachability *reachability = ((Reachability*)info); -#endif - - // we probably dont need an autoreleasepool here as GCD docs state each queue has its own autorelease pool - // but what the heck eh? - @autoreleasepool - { - [reachability reachabilityChanged:flags]; - } -} - - -@implementation Reachability - -@synthesize reachabilityRef; -@synthesize reachabilitySerialQueue; - -@synthesize reachableOnWWAN; - -@synthesize reachableBlock; -@synthesize unreachableBlock; - -@synthesize reachabilityObject; - -#pragma mark - class constructor methods -+(Reachability*)reachabilityWithHostname:(NSString*)hostname -{ - SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithName(NULL, [hostname UTF8String]); - if (ref) - { - id reachability = [[self alloc] initWithReachabilityRef:ref]; - -#if __has_feature(objc_arc) - return reachability; -#else - return [reachability autorelease]; -#endif - - } - - return nil; -} - -+(Reachability *)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress -{ - SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress); - if (ref) - { - id reachability = [[self alloc] initWithReachabilityRef:ref]; - -#if __has_feature(objc_arc) - return reachability; -#else - return [reachability autorelease]; -#endif - } - - return nil; -} - -+(Reachability *)reachabilityForInternetConnection -{ - struct sockaddr_in zeroAddress; - bzero(&zeroAddress, sizeof(zeroAddress)); - zeroAddress.sin_len = sizeof(zeroAddress); - zeroAddress.sin_family = AF_INET; - - return [self reachabilityWithAddress:&zeroAddress]; -} - -+(Reachability*)reachabilityForLocalWiFi -{ - struct sockaddr_in localWifiAddress; - bzero(&localWifiAddress, sizeof(localWifiAddress)); - localWifiAddress.sin_len = sizeof(localWifiAddress); - localWifiAddress.sin_family = AF_INET; - // IN_LINKLOCALNETNUM is defined in as 169.254.0.0 - localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM); - - return [self reachabilityWithAddress:&localWifiAddress]; -} - - -// initialization methods - --(Reachability *)initWithReachabilityRef:(SCNetworkReachabilityRef)ref -{ - self = [super init]; - if (self != nil) - { - self.reachableOnWWAN = YES; - self.reachabilityRef = ref; - } - - return self; -} - --(void)dealloc -{ - [self stopNotifier]; - - if(self.reachabilityRef) - { - CFRelease(self.reachabilityRef); - self.reachabilityRef = nil; - } - - -#if !(__has_feature(objc_arc)) - [super dealloc]; -#endif - - -} - -#pragma mark - notifier methods - -// Notifier -// NOTE: this uses GCD to trigger the blocks - they *WILL NOT* be called on THE MAIN THREAD -// - In other words DO NOT DO ANY UI UPDATES IN THE BLOCKS. -// INSTEAD USE dispatch_async(dispatch_get_main_queue(), ^{UISTUFF}) (or dispatch_sync if you want) - --(BOOL)startNotifier -{ - SCNetworkReachabilityContext context = { 0, NULL, NULL, NULL, NULL }; - - // this should do a retain on ourself, so as long as we're in notifier mode we shouldn't disappear out from under ourselves - // woah - self.reachabilityObject = self; - - - - // first we need to create a serial queue - // we allocate this once for the lifetime of the notifier - self.reachabilitySerialQueue = dispatch_queue_create("com.tonymillion.reachability", NULL); - if(!self.reachabilitySerialQueue) - { - return NO; - } - -#if __has_feature(objc_arc) - context.info = (__bridge void *)self; -#else - context.info = (void *)self; -#endif - - if (!SCNetworkReachabilitySetCallback(self.reachabilityRef, TMReachabilityCallback, &context)) - { -#ifdef DEBUG - NSLog(@"SCNetworkReachabilitySetCallback() failed: %s", SCErrorString(SCError())); -#endif - - //clear out the dispatch queue - if(self.reachabilitySerialQueue) - { -#if NEEDS_DISPATCH_RETAIN_RELEASE - dispatch_release(self.reachabilitySerialQueue); -#endif - self.reachabilitySerialQueue = nil; - } - - self.reachabilityObject = nil; - - return NO; - } - - // set it as our reachability queue which will retain the queue - if(!SCNetworkReachabilitySetDispatchQueue(self.reachabilityRef, self.reachabilitySerialQueue)) - { -#ifdef DEBUG - NSLog(@"SCNetworkReachabilitySetDispatchQueue() failed: %s", SCErrorString(SCError())); -#endif - - //UH OH - FAILURE! - - // first stop any callbacks! - SCNetworkReachabilitySetCallback(self.reachabilityRef, NULL, NULL); - - // then clear out the dispatch queue - if(self.reachabilitySerialQueue) - { -#if NEEDS_DISPATCH_RETAIN_RELEASE - dispatch_release(self.reachabilitySerialQueue); -#endif - self.reachabilitySerialQueue = nil; - } - - self.reachabilityObject = nil; - - return NO; - } - - return YES; -} - --(void)stopNotifier -{ - // first stop any callbacks! - SCNetworkReachabilitySetCallback(self.reachabilityRef, NULL, NULL); - - // unregister target from the GCD serial dispatch queue - SCNetworkReachabilitySetDispatchQueue(self.reachabilityRef, NULL); - - if(self.reachabilitySerialQueue) - { -#if NEEDS_DISPATCH_RETAIN_RELEASE - dispatch_release(self.reachabilitySerialQueue); -#endif - self.reachabilitySerialQueue = nil; - } - - self.reachabilityObject = nil; -} - -#pragma mark - reachability tests - -// this is for the case where you flick the airplane mode -// you end up getting something like this: -//Reachability: WR ct----- -//Reachability: -- ------- -//Reachability: WR ct----- -//Reachability: -- ------- -// we treat this as 4 UNREACHABLE triggers - really apple should do better than this - -#define testcase (kSCNetworkReachabilityFlagsConnectionRequired | kSCNetworkReachabilityFlagsTransientConnection) - --(BOOL)isReachableWithFlags:(SCNetworkReachabilityFlags)flags -{ - BOOL connectionUP = YES; - - if(!(flags & kSCNetworkReachabilityFlagsReachable)) - connectionUP = NO; - - if( (flags & testcase) == testcase ) - connectionUP = NO; - -#if TARGET_OS_IPHONE - if(flags & kSCNetworkReachabilityFlagsIsWWAN) - { - // we're on 3G - if(!self.reachableOnWWAN) - { - // we dont want to connect when on 3G - connectionUP = NO; - } - } -#endif - - return connectionUP; -} - --(BOOL)isReachable -{ - SCNetworkReachabilityFlags flags; - - if(!SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) - return NO; - - return [self isReachableWithFlags:flags]; -} - --(BOOL)isReachableViaWWAN -{ -#if TARGET_OS_IPHONE - - SCNetworkReachabilityFlags flags = 0; - - if(SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) - { - // check we're REACHABLE - if(flags & kSCNetworkReachabilityFlagsReachable) - { - // now, check we're on WWAN - if(flags & kSCNetworkReachabilityFlagsIsWWAN) - { - return YES; - } - } - } -#endif - - return NO; -} - --(BOOL)isReachableViaWiFi -{ - SCNetworkReachabilityFlags flags = 0; - - if(SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) - { - // check we're reachable - if((flags & kSCNetworkReachabilityFlagsReachable)) - { -#if TARGET_OS_IPHONE - // check we're NOT on WWAN - if((flags & kSCNetworkReachabilityFlagsIsWWAN)) - { - return NO; - } -#endif - return YES; - } - } - - return NO; -} - - -// WWAN may be available, but not active until a connection has been established. -// WiFi may require a connection for VPN on Demand. --(BOOL)isConnectionRequired -{ - return [self connectionRequired]; -} - --(BOOL)connectionRequired -{ - SCNetworkReachabilityFlags flags; - - if(SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) - { - return (flags & kSCNetworkReachabilityFlagsConnectionRequired); - } - - return NO; -} - -// Dynamic, on demand connection? --(BOOL)isConnectionOnDemand -{ - SCNetworkReachabilityFlags flags; - - if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) - { - return ((flags & kSCNetworkReachabilityFlagsConnectionRequired) && - (flags & (kSCNetworkReachabilityFlagsConnectionOnTraffic | kSCNetworkReachabilityFlagsConnectionOnDemand))); - } - - return NO; -} - -// Is user intervention required? --(BOOL)isInterventionRequired -{ - SCNetworkReachabilityFlags flags; - - if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) - { - return ((flags & kSCNetworkReachabilityFlagsConnectionRequired) && - (flags & kSCNetworkReachabilityFlagsInterventionRequired)); - } - - return NO; -} - - -#pragma mark - reachability status stuff - --(NetworkStatus)currentReachabilityStatus -{ - if([self isReachable]) - { - if([self isReachableViaWiFi]) - return ReachableViaWiFi; - -#if TARGET_OS_IPHONE - return ReachableViaWWAN; -#endif - } - - return NotReachable; -} - --(SCNetworkReachabilityFlags)reachabilityFlags -{ - SCNetworkReachabilityFlags flags = 0; - - if(SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) - { - return flags; - } - - return 0; -} - --(NSString*)currentReachabilityString -{ - NetworkStatus temp = [self currentReachabilityStatus]; - - if(temp == reachableOnWWAN) - { - // updated for the fact we have CDMA phones now! - return NSLocalizedString(@"Cellular", @""); - } - if (temp == ReachableViaWiFi) - { - return NSLocalizedString(@"WiFi", @""); - } - - return NSLocalizedString(@"No Connection", @""); -} - --(NSString*)currentReachabilityFlags -{ - return reachabilityFlags([self reachabilityFlags]); -} - -#pragma mark - callback function calls this method - --(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags -{ - if([self isReachableWithFlags:flags]) - { - if(self.reachableBlock) - { - self.reachableBlock(self); - } - } - else - { - if(self.unreachableBlock) - { - self.unreachableBlock(self); - } - } - - // this makes sure the change notification happens on the MAIN THREAD - dispatch_async(dispatch_get_main_queue(), ^{ - [[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification - object:self]; - }); -} - -#pragma mark - Debug Description - -- (NSString *) description; -{ - NSString *description = [NSString stringWithFormat:@"<%@: %#x>", - NSStringFromClass([self class]), (unsigned int) self]; - return description; -} - -@end diff --git a/GameCenterManager/GameCenterManager-Info.plist b/GameCenterManager/GameCenterManager-Info.plist index bc2d119..2d615ef 100755 --- a/GameCenterManager/GameCenterManager-Info.plist +++ b/GameCenterManager/GameCenterManager-Info.plist @@ -28,11 +28,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 5.1 + 5.2 CFBundleSignature ???? CFBundleVersion - 5.1 + 5.2 LSRequiresIPhoneOS UIMainStoryboardFile @@ -48,7 +48,6 @@ UISupportedInterfaceOrientations UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown UISupportedInterfaceOrientations~ipad diff --git a/GameCenterManager/Icons/AppIcon29x29.png b/GameCenterManager/Icons/AppIcon29x29.png deleted file mode 100755 index 8098537..0000000 Binary files a/GameCenterManager/Icons/AppIcon29x29.png and /dev/null differ diff --git a/GameCenterManager/Icons/AppIcon29x29@2x.png b/GameCenterManager/Icons/AppIcon29x29@2x.png deleted file mode 100755 index 8dc8f6d..0000000 Binary files a/GameCenterManager/Icons/AppIcon29x29@2x.png and /dev/null differ diff --git a/GameCenterManager/Icons/AppIcon40x40.png b/GameCenterManager/Icons/AppIcon40x40.png deleted file mode 100755 index 2b2c912..0000000 Binary files a/GameCenterManager/Icons/AppIcon40x40.png and /dev/null differ diff --git a/GameCenterManager/Icons/AppIcon40x40@2x.png b/GameCenterManager/Icons/AppIcon40x40@2x.png deleted file mode 100755 index 065cb21..0000000 Binary files a/GameCenterManager/Icons/AppIcon40x40@2x.png and /dev/null differ diff --git a/GameCenterManager/Icons/AppIcon57x57.png b/GameCenterManager/Icons/AppIcon57x57.png deleted file mode 100755 index 910d9ba..0000000 Binary files a/GameCenterManager/Icons/AppIcon57x57.png and /dev/null differ diff --git a/GameCenterManager/Icons/AppIcon60x60.png b/GameCenterManager/Icons/AppIcon60x60.png deleted file mode 100755 index bf33247..0000000 Binary files a/GameCenterManager/Icons/AppIcon60x60.png and /dev/null differ diff --git a/GameCenterManager/Icons/AppIcon60x60@2x.png b/GameCenterManager/Icons/AppIcon60x60@2x.png deleted file mode 100755 index fc1e05c..0000000 Binary files a/GameCenterManager/Icons/AppIcon60x60@2x.png and /dev/null differ diff --git a/GameCenterManager/Icons/AppIcon76x76.png b/GameCenterManager/Icons/AppIcon76x76.png deleted file mode 100755 index 8b09399..0000000 Binary files a/GameCenterManager/Icons/AppIcon76x76.png and /dev/null differ diff --git a/GameCenterManager/Icons/AppIcon76x76@2x.png b/GameCenterManager/Icons/AppIcon76x76@2x.png deleted file mode 100755 index 7d05a92..0000000 Binary files a/GameCenterManager/Icons/AppIcon76x76@2x.png and /dev/null differ diff --git a/GameCenterManager/Icons/iTunesArtwork.png b/GameCenterManager/Icons/iTunesArtwork.png deleted file mode 100755 index 2c64dcb..0000000 Binary files a/GameCenterManager/Icons/iTunesArtwork.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/AppIcon.appiconset/AppIcon29x29.png b/GameCenterManager/Images.xcassets/AppIcon.appiconset/AppIcon29x29.png deleted file mode 100755 index 8098537..0000000 Binary files a/GameCenterManager/Images.xcassets/AppIcon.appiconset/AppIcon29x29.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/AppIcon.appiconset/AppIcon29x29@2x.png b/GameCenterManager/Images.xcassets/AppIcon.appiconset/AppIcon29x29@2x.png deleted file mode 100755 index 8dc8f6d..0000000 Binary files a/GameCenterManager/Images.xcassets/AppIcon.appiconset/AppIcon29x29@2x.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/AppIcon.appiconset/AppIcon40x40@2x.png b/GameCenterManager/Images.xcassets/AppIcon.appiconset/AppIcon40x40@2x.png deleted file mode 100755 index 065cb21..0000000 Binary files a/GameCenterManager/Images.xcassets/AppIcon.appiconset/AppIcon40x40@2x.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/AppIcon.appiconset/AppIcon60x60@2x.png b/GameCenterManager/Images.xcassets/AppIcon.appiconset/AppIcon60x60@2x.png deleted file mode 100755 index fc1e05c..0000000 Binary files a/GameCenterManager/Images.xcassets/AppIcon.appiconset/AppIcon60x60@2x.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/AppIcon.appiconset/Contents.json b/GameCenterManager/Images.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100755 index 051d91f..0000000 --- a/GameCenterManager/Images.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "images" : [ - { - "size" : "29x29", - "idiom" : "iphone", - "filename" : "AppIcon29x29.png", - "scale" : "1x" - }, - { - "size" : "29x29", - "idiom" : "iphone", - "filename" : "AppIcon29x29@2x.png", - "scale" : "2x" - }, - { - "size" : "40x40", - "idiom" : "iphone", - "filename" : "AppIcon40x40@2x.png", - "scale" : "2x" - }, - { - "size" : "57x57", - "idiom" : "iphone", - "filename" : "Icon.png", - "scale" : "1x" - }, - { - "size" : "57x57", - "idiom" : "iphone", - "filename" : "Icon@2x.png", - "scale" : "2x" - }, - { - "size" : "60x60", - "idiom" : "iphone", - "filename" : "AppIcon60x60@2x.png", - "scale" : "2x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/GameCenterManager/Images.xcassets/AppIcon.appiconset/Icon.png b/GameCenterManager/Images.xcassets/AppIcon.appiconset/Icon.png deleted file mode 100755 index bd8da2e..0000000 Binary files a/GameCenterManager/Images.xcassets/AppIcon.appiconset/Icon.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/AppIcon.appiconset/Icon@2x.png b/GameCenterManager/Images.xcassets/AppIcon.appiconset/Icon@2x.png deleted file mode 100755 index 715341d..0000000 Binary files a/GameCenterManager/Images.xcassets/AppIcon.appiconset/Icon@2x.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/LaunchImage.launchimage/Contents.json b/GameCenterManager/Images.xcassets/LaunchImage.launchimage/Contents.json deleted file mode 100755 index ce5e4a3..0000000 --- a/GameCenterManager/Images.xcassets/LaunchImage.launchimage/Contents.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "images" : [ - { - "orientation" : "portrait", - "idiom" : "iphone", - "filename" : "Default@2x.png", - "minimum-system-version" : "7.0", - "scale" : "2x" - }, - { - "orientation" : "portrait", - "idiom" : "iphone", - "filename" : "Default-568h@2x.png", - "minimum-system-version" : "7.0", - "subtype" : "retina4", - "scale" : "2x" - }, - { - "orientation" : "portrait", - "idiom" : "iphone", - "filename" : "Default.png", - "scale" : "1x" - }, - { - "orientation" : "portrait", - "idiom" : "iphone", - "filename" : "Default@2x.png", - "scale" : "2x" - }, - { - "orientation" : "portrait", - "idiom" : "iphone", - "filename" : "Default-568h@2x.png", - "subtype" : "retina4", - "scale" : "2x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/GameCenterManager/Images.xcassets/LaunchImage.launchimage/Default-568h@2x.png b/GameCenterManager/Images.xcassets/LaunchImage.launchimage/Default-568h@2x.png deleted file mode 100755 index 2775742..0000000 Binary files a/GameCenterManager/Images.xcassets/LaunchImage.launchimage/Default-568h@2x.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/LaunchImage.launchimage/Default.png b/GameCenterManager/Images.xcassets/LaunchImage.launchimage/Default.png deleted file mode 100755 index f6c4263..0000000 Binary files a/GameCenterManager/Images.xcassets/LaunchImage.launchimage/Default.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/LaunchImage.launchimage/Default@2x.png b/GameCenterManager/Images.xcassets/LaunchImage.launchimage/Default@2x.png deleted file mode 100755 index 679ac16..0000000 Binary files a/GameCenterManager/Images.xcassets/LaunchImage.launchimage/Default@2x.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/Contents.json b/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/Contents.json deleted file mode 100755 index 366bee5..0000000 --- a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/Contents.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "images" : [ - { - "size" : "16x16", - "idiom" : "mac", - "filename" : "GK Icon-16.png", - "scale" : "1x" - }, - { - "size" : "16x16", - "idiom" : "mac", - "filename" : "GK Icon-16@2x.png", - "scale" : "2x" - }, - { - "size" : "32x32", - "idiom" : "mac", - "filename" : "GK Icon-32.png", - "scale" : "1x" - }, - { - "size" : "32x32", - "idiom" : "mac", - "filename" : "GK Icon-32@2x.png", - "scale" : "2x" - }, - { - "size" : "128x128", - "idiom" : "mac", - "filename" : "GK Icon-128.png", - "scale" : "1x" - }, - { - "size" : "128x128", - "idiom" : "mac", - "filename" : "GK Icon-128@2x.png", - "scale" : "2x" - }, - { - "size" : "256x256", - "idiom" : "mac", - "filename" : "GK Icon-256.png", - "scale" : "1x" - }, - { - "size" : "256x256", - "idiom" : "mac", - "filename" : "GK Icon-256@2x.png", - "scale" : "2x" - }, - { - "size" : "512x512", - "idiom" : "mac", - "filename" : "GK Icon-512.png", - "scale" : "1x" - }, - { - "size" : "512x512", - "idiom" : "mac", - "filename" : "GK Icon-512@2x.png", - "scale" : "2x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-128.png b/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-128.png deleted file mode 100755 index dd9c0a5..0000000 Binary files a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-128.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-128@2x.png b/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-128@2x.png deleted file mode 100755 index 4ba7634..0000000 Binary files a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-128@2x.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-16.png b/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-16.png deleted file mode 100755 index 1cdaff9..0000000 Binary files a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-16.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-16@2x.png b/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-16@2x.png deleted file mode 100755 index ddceb65..0000000 Binary files a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-16@2x.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-256.png b/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-256.png deleted file mode 100755 index 4ba7634..0000000 Binary files a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-256.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-256@2x.png b/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-256@2x.png deleted file mode 100755 index 84a5ebe..0000000 Binary files a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-256@2x.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-32.png b/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-32.png deleted file mode 100755 index ddceb65..0000000 Binary files a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-32.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-32@2x.png b/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-32@2x.png deleted file mode 100755 index adad812..0000000 Binary files a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-32@2x.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-512.png b/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-512.png deleted file mode 100755 index 84a5ebe..0000000 Binary files a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-512.png and /dev/null differ diff --git a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-512@2x.png b/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-512@2x.png deleted file mode 100755 index 2a4d561..0000000 Binary files a/GameCenterManager/Images.xcassets/MacAppIcon.appiconset/GK Icon-512@2x.png and /dev/null differ diff --git a/GameCenterManager/ViewController.m b/GameCenterManager/ViewController.m index 3d86c07..97d9621 100755 --- a/GameCenterManager/ViewController.m +++ b/GameCenterManager/ViewController.m @@ -23,9 +23,9 @@ - (void)viewDidLoad { // Setup ViewController Appearance scrollView.contentSize = CGSizeMake(320, 450); - playerPicture.layer.cornerRadius = 25; + playerPicture.layer.cornerRadius = playerPicture.frame.size.height/2; playerPicture.layer.masksToBounds = YES; - [actionBarLabel setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15<=10], NSFontAttributeName,nil] forState:UIControlStateNormal]; + [actionBarLabel setTitleTextAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:10]} forState:UIControlStateNormal]; // Set GameCenter Manager Delegate [[GameCenterManager sharedManager] setDelegate:self]; @@ -195,36 +195,36 @@ - (void)gameCenterManager:(GameCenterManager *)manager availabilityChanged:(NSDi } - (void)gameCenterManager:(GameCenterManager *)manager error:(NSError *)error { - NSLog(@"GC Error: %@", error); + NSLog(@"GCM Error: %@", error); actionBarLabel.title = error.domain; } -- (void)gameCenterManager:(GameCenterManager *)manager reportedScore:(NSDictionary *)scoreInformation { - NSLog(@"GC Reported Score: %@", scoreInformation); - actionBarLabel.title = [NSString stringWithFormat:@"Reported leaderboard score to GameCenter."]; -} - -- (void)gameCenterManager:(GameCenterManager *)manager savedScore:(GKScore *)score { - NSLog(@"Saved GC Score with value: %lld", score.value); - actionBarLabel.title = [NSString stringWithFormat:@"Score saved for upload to GameCenter."]; +- (void)gameCenterManager:(GameCenterManager *)manager reportedAchievement:(GKAchievement *)achievement withError:(NSError *)error { + if (!error) { + NSLog(@"GCM Reported Achievement: %@", achievement); + actionBarLabel.title = [NSString stringWithFormat:@"Reported achievement with %.1f percent completed", achievement.percentComplete]; + } else { + NSLog(@"GCM Error while reporting achievement: %@", error); + } } -- (void)gameCenterManager:(GameCenterManager *)manager savedAchievement:(NSDictionary *)achievementInformation { - NSLog(@"Saved GC Achievement, %@", [achievementInformation objectForKey:@"id"]); - actionBarLabel.title = [NSString stringWithFormat:@"Achievement saved for upload to GameCenter."]; +- (void)gameCenterManager:(GameCenterManager *)manager reportedScore:(GKScore *)score withError:(NSError *)error { + if (!error) { + NSLog(@"GCM Reported Score: %@", score); + actionBarLabel.title = [NSString stringWithFormat:@"Reported leaderboard score: %lld", score.value]; + } else { + NSLog(@"GCM Error while reporting score: %@", error); + } } -- (void)gameCenterManager:(GameCenterManager *)manager reportedAchievement:(NSDictionary *)achievementInformation { - NSLog(@"GC Reported Achievement: %@", achievementInformation); - actionBarLabel.title = [NSString stringWithFormat:@"Reported achievement to GameCenter."]; +- (void)gameCenterManager:(GameCenterManager *)manager didSaveScore:(GKScore *)score { + NSLog(@"Saved GCM Score with value: %lld", score.value); + actionBarLabel.title = [NSString stringWithFormat:@"Score saved for upload to GameCenter."]; } -- (void)gameCenterManager:(GameCenterManager *)manager resetAchievements:(NSError *)error { - if (error) { - actionBarLabel.title = [NSString stringWithFormat:@"Error reseting all GameCenter achievements."]; - } else { - actionBarLabel.title = [NSString stringWithFormat:@"Reset all GameCenter achievements."]; - } +- (void)gameCenterManager:(GameCenterManager *)manager didSaveAchievement:(GKAchievement *)achievement { + NSLog(@"Saved GCM Achievement: %@", achievement); + actionBarLabel.title = [NSString stringWithFormat:@"Achievement saved for upload to GameCenter."]; } //------------------------------------------------------------------------------------------------------------// diff --git a/GameCenterManager/en.lproj/Storyboard_iPhone.storyboard b/GameCenterManager/en.lproj/Storyboard_iPhone.storyboard index 0bb66b5..b780cb8 100755 --- a/GameCenterManager/en.lproj/Storyboard_iPhone.storyboard +++ b/GameCenterManager/en.lproj/Storyboard_iPhone.storyboard @@ -1,11 +1,11 @@ - + - - + + - + @@ -156,7 +156,7 @@ - + diff --git a/Images.xcassets/FeltTile.imageset/Contents.json b/Images.xcassets/FeltTile.imageset/Contents.json new file mode 100644 index 0000000..601d4b6 --- /dev/null +++ b/Images.xcassets/FeltTile.imageset/Contents.json @@ -0,0 +1,17 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "FeltTile.png" + }, + { + "idiom" : "universal", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/GameCenterManager Mac/Images/FeltTile.png b/Images.xcassets/FeltTile.imageset/FeltTile.png old mode 100755 new mode 100644 similarity index 100% rename from GameCenterManager Mac/Images/FeltTile.png rename to Images.xcassets/FeltTile.imageset/FeltTile.png diff --git a/Images.xcassets/MacHeader.imageset/Contents.json b/Images.xcassets/MacHeader.imageset/Contents.json new file mode 100644 index 0000000..4252977 --- /dev/null +++ b/Images.xcassets/MacHeader.imageset/Contents.json @@ -0,0 +1,17 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "MacHeader.png" + }, + { + "idiom" : "universal", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/GameCenterManager Mac/Images/MacHeader.png b/Images.xcassets/MacHeader.imageset/MacHeader.png old mode 100755 new mode 100644 similarity index 100% rename from GameCenterManager Mac/Images/MacHeader.png rename to Images.xcassets/MacHeader.imageset/MacHeader.png diff --git a/Images.xcassets/TopBar.imageset/Contents.json b/Images.xcassets/TopBar.imageset/Contents.json new file mode 100644 index 0000000..f83682d --- /dev/null +++ b/Images.xcassets/TopBar.imageset/Contents.json @@ -0,0 +1,17 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "TopBar.png" + }, + { + "idiom" : "universal", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/GameCenterManager Mac/Images/TopBar.png b/Images.xcassets/TopBar.imageset/TopBar.png old mode 100755 new mode 100644 similarity index 100% rename from GameCenterManager Mac/Images/TopBar.png rename to Images.xcassets/TopBar.imageset/TopBar.png diff --git a/README.md b/README.md index 0282bc8..a8591af 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ GameCenter Manager ========================= -GameCenter Manager helps you manage Game Center in your iOS or Mac app. It makes it easy to 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. In future updates, GameCenter Manager will make it easy to setup and run live Game Center Multiplayer matches. +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. In future updates, GameCenter Manager will make it easy to setup and run live Game Center Multiplayer matches. @@ -10,12 +10,12 @@ Setup 1. Add the `GameKit` and `SystemConfiguration` frameworks to your Xcode project 2. Add the following classes (can be found in the *GC Manager* folder) to your Xcode project (make sure to select Copy Items in the dialog): - - GameCenterManager (GameCenterManager-Mac on OS X) + - GameCenterManager - Reachability - NSDataAES256 -3. Open the `GameCenterManager.h` (`GameCenterManager-Mac.h` on OS X) file and change the `kGameCenterManagerKey` constant to the secret key you want to use for encryption/decryption -4. Import the `GameCenterManager.h` file (`GameCenterManager-Mac.h` on OS X) -5. Initialize GameCenter Manager and begin Syncing by using the following method call (preferrably in your `appDidFinishLaunching` method of your AppDelegate): +3. Open the `GameCenterManager.h` file and change the `kGameCenterManagerKey` constant to the secret key you want to use for encryption / decryption +4. Import the `GameCenterManager.h` file +5. Initialize GameCenter Manager and begin Syncing by using the following method call: [[GameCenterManager sharedManager] initGameCenter]; @@ -33,16 +33,16 @@ Documentation All methods, properties, types, and delegate methods available on the GameCenterManager class are documented below. If you're using [Xcode 5](https://developer.apple.com/technologies/tools/whats-new.html) with GameCenterManager, documentation is available directly within Xcode (just Option-Click any method for Quick Help). ###Initialize GameCenterManager -You should initialize GameCenterManager when your app is launched, preferably in the `application didFinishLaunchingWithOptions` method. +You should initialize GameCenterManager when your app is launched - [[GameCenterManager sharedManager] initGameCenter]; + [[GameCenterManager sharedManager] initGameCenter]; This checks if Game Center is supported in the current device, authenticates the player and synchronizes scores and achievements from Game Center if its being run for the first time. ###Check Game Center Support GameCenter Manager automatically checks if Game Center is available before performing any Game Center-related operations. You can also check for Game Center availability by using the following method, which returns a `BOOL` value (YES / NO). - BOOL isAvailable = [[GameCenterManager sharedManager] checkGameCenterAvailability]; + BOOL isAvailable = [[GameCenterManager sharedManager] checkGameCenterAvailability]; This method will perform the following checks in the following order: 1. Current OS version new enough to run Game Center. iOS 4.1 or OS X 10.8. Some Game Center methods require newer OS versions which will be checked (ex. challenges and some multiplayer features). @@ -50,19 +50,19 @@ This method will perform the following checks in the following order: 3. Internet Connection. The `Reachability` class is used to determine if there is an active internet connection. GameCenterManager will still work without internet, however all saved data can only be uploaded with an internet connection. 4. Local Player. Check to make sure a local player is logged in and authenticated. -This method may return **NO** in many cases. Use the `gameCenterManager: availabilityChanged:` delegate method to get an `NSDictionary` containing information about why Game Center is or isn't available. Refer to the section on delegate methods below. +This method may return **NO** in many cases. Use the `gameCenterManager:availabilityChanged:` delegate method to get an `NSDictionary` containing information about why Game Center is or isn't available. Refer to the section on delegate methods below. ###Report Score Report a score to Game Center using a Game Center Leaderboard ID. The score is saved locally then uploaded to Game Center (if Game Center is available). - [[GameCenterManager sharedManager] saveAndReportScore:1000 leaderboard:@"Leaderboard ID" sortOrder:GameCenterSortOrder]; + [[GameCenterManager sharedManager] saveAndReportScore:1000 leaderboard:@"Leaderboard ID" sortOrder:GameCenterSortOrder]; Set the Game Center Sort Order (either `GameCenterSortOrderHighToLow` or `GameCenterSortOrderLowToHigh`) to report a score to Game Center only if the new score is better than the best one (depending on the sort order). There is no need for you to find out if a user has beat their highscore before submitting it - GameCenterManager will determine if the score should be submitted based on the parameters provided. ###Report Achievement Report an achievement to Game Center using a Game Center Achievement ID. The achievement and its percent complete are saved locally then uploaded to Game Center (if Game Center is available). - [[GameCenterManager sharedManager] saveAndReportAchievement:@"Achievement ID" percentComplete:50]; + [[GameCenterManager sharedManager] saveAndReportAchievement:@"Achievement ID" percentComplete:50]; The `percentComplete` parameter specifies how much progress the user has made on an achievement. Specifiying a value of 100 will mark the achievement as completed. Values submitted between 1-99 will display in Game Center and show the user that they need to make more progress to earn an achievement. if you specify an achievement percent complete lower than the current percent complete, it will be ignored by Game Center. @@ -124,7 +124,7 @@ To get the player's display name (alias on iOS lower than iOS 6.0) use this meth To get the player's profile picture the following method. On iOS, the completion handler passes a `UIImage`, on OS X the completion handler passes an `NSImage`. The image passed to you is at full resolution. - [self localPlayerPhoto:^(UIImage *playerPhoto) { + [self localPlayerPhoto:^(UIImage *playerPhoto) { // On OS X, the completion handler pases an NSImage instead of a UIImage UIImageView *imageView = [[UIImageView alloc] initWithImage:playerPhoto]; }];