GameCenterManager
iOS Game Center helper singleton
Install / Use
/learn @nihalahmed/GameCenterManagerREADME
A Note on Swift Conversion
This branch of the project is currently being refactored and rewritten in Swift. Please contibute to help finish the conversion and improve the project. Once completed, the projct will switch over to Swift from Objective-C. Until that time, this branch is not ready for production use.
<img width=100% src="https://raw.github.com/nihalahmed/GameCenterManager/master/Images/GameBanner.png"/>GameCenter Manager helps to manage Game Center in iOS and Mac apps. Report and track 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. On iOS (and soon on other platforms) GameCenter Manager makes it easy to setup and run live peer-to-peer Game Center Multiplayer matches.
If you like the project, please star it on GitHub! Watch the project on GitHub for updates. If you use GameCenter Manager in your app, send an email to contact@iraremedia.com or let us know on Twitter @iRareMedia.
Project Features
GameCenter Manager is a great way to use Game Center in your iOS or OS X app. Below are a few key project features and highlights.
- Sync, submit, save, retrieve, and track any Game Center leaderboards, achievements, or challenges in only one line of code.
- Setup and manage peer-to-peer multiplayer Game Center matches
- Just drag and drop the files into your project - no complicated setup
- Useful delegate methods and properties let you access and manage advanced Game Center features
- iOS / OS X sample apps illustrate how easy it is to use GameCenter Manager
Project Information
Learn more about the project requirements, licensing, and contributions.
Requirements
- Built with and for Objective-C ARC
- Requires a minimum of iOS 7.0 / OS X 10.9 as the deployment target
- Requires Xcode 5.0.1 for use in any iOS Project
- Uses Apple LLVM compiler 5.0
Requirements
- Requires iOS 7.0+ or OS X 10.9+. The sample project is optimized for iOS 8 and OS X 10.10.
- Requires Automatic Reference Counting (ARC).
- Optimized for ARM64 Architecture
Requires Xcode 6 for use in any iOS or OS X project. Requires a minimum of iOS 7.0 or OS X 10.9 as the deployment target.
| Current Build Target | Earliest Supported Build Target | Earliest Compatible Build Target | |:--------------------: |:-------------------------------: |:--------------------------------: | | iOS 9.0 | iOS 7.0 | iOS 7.0 | | OS X 10.11 | OS X 10.9 | OS X 10.9 | | Xcode 7.1 | Xcode 6.1.1 | Xcode 6.0 | | LLVM 6.1 | LLVM 6.1 | LLVM 5.0 |
REQUIREMENTS NOTE
Supported means that the library has been tested with this version. Compatible means that the library should work on this OS version (i.e. it doesn't rely on any unavailable SDK features) but is no longer being tested for compatibility and may require tweaking or bug fixes to run correctly.
License
You are free to make changes and use this in either personal or commercial projects. Attribution is not required, but is appreciated. We have spent a lot of time, energy, and resources working on this project - so a little Thanks! (or something to that affect) would be much appreciated. If you use GameCenter Manager in your app, send an email to contact@iraremedia.com or let us know on Twitter @iRareMedia. See the full GameCenter Manager license here.
Contributions
Any contribution is more than welcome! You can contribute through pull requests and issues on GitHub.
Sample App
GameCenter Manager's demo app makes it easier to test Game Center integration with GameCenter Manager on both Mac and iOS. It also lays out how to use the GameCenterManager class. We recommend that you leave the Bundle ID provided with the Demo App as-is. This Bundle ID is already linked to a Game Center game in iTunes Connect with scores and achievements. You may, however, substitute your own Bundle ID and entitlements file.
Documentation
All methods, properties, types, and delegate methods available on the GameCenterManager class are documented below. If you're using Xcode 5 with GameCenter Manager, documentation is available directly within Xcode (just Option-Click any method for Quick Help).
Setup
Setting up GameCenter Manager is very straightforward. These instructions do not detail how to enable Game Center in your app. You need to setup Game Center before using GameCenter Manager. Refer to the wiki pages for details on that.
-
Add the
GameKit,SystemConfiguration, andSecurityframeworks to your Xcode project -
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
- Reachability
- NSDataAES256
-
Import the
GameCenterManager.hfile -
You can initialize GameCenterManager and begin syncing by using the following method call:
[[GameCenterManager sharedManager] setupManager]; // Or use setupManagerAndSetShouldCryptWithKey: for use with encryption -
Add the delegate
GameCenterManagerDelegateto your header file, then set the delegate in your implementation and add any delegate methods you'd like to use (see Delegates):[[GameCenterManager sharedManager] setDelegate:self];
Methods
There are many methods available on iCloud Document Sync. The most important / highlight methods are documented below. All other methods are documented in the docset and with in-code comments.
Initialize GameCenterManager
You should setup GameCenterManager when your app is launched. This should only be done once and can be done in the application: didFinishLaunchingWithOptions: method of your AppDelegate.
[[GameCenterManager sharedManager] setupManager];
This initializes GameCenter Manager, checks if Game Center is supported on the current device, authenticates the player and synchronizes scores and achievements from Game Center. Alternatively, you can call the following method to enable encryption of local data:
[[GameCenterManager sharedManager] setupManagerAndSetShouldCryptWithKey:@"YourKey"];
These methods are not interchangable. If you decide to setup with encryption then you should never revert to setting up without encryption, and vice versa. Doing so will cause issues with archiving and unarchiving the saved data - which results in a crash. Pick one and stick with it forever. If you do change it, you'll need to delete the GameCenterManager.plist file from your app's library (inside the bundle).
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).
// Will not call delegate if status has not changed from the previous time it was called
BOOL isAvailable = [[GameCenterManager sharedManager] checkGameCenterAvailability:NO];
// Will always call delegate even if status has not changed from the previous time it was called
BOOL isAvailable = [[GameCenterManager sharedManager] checkGameCenterAvailability:YES];
This method will perform the following checks in the following order:
- 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).
- GameKit API availability. The
GKLocalPlayerclass must be available at a minimum. - Internet Connection. The
Reachabilityclass 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. - 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.
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];
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];
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
