I'm trying to implement Game Center in my Swift game. I have a menu view controller, where the user can press a "SCORES" button, which should take them to the Game Center view controller.
This is the code that runs in the menu vc, when the button is pressed:
var gcViewController: GKGameCenterViewController = GKGameCenterViewController()
gcViewController.gameCenterDelegate = self
gcViewController.viewState = GKGameCenterViewControllerState.Leaderboards
gcViewController.leaderboardIdentifier = "VHS"
self.presentViewController(gcViewController, animated: true, completion: nil)
I have code in the Game Center vc, but I don't think it gets a chance to run. The app stops execution after this code (no breakpoints or errors, just won't let me tap anything) and displays a pop up message that reads:
Game Center Unavailable
Player is not signed in
The only other response I get is in Xcode, where the following line is printed to the log:
2014-08-29 14:10:33.157 Valley[2291:304785] 17545849:_UIScreenEdgePanRecognizerEdgeSettings.edgeRegionSize=13.000000
I have no idea what this means or why Game Center is not working. Can anybody help??
I solved this problem for TEST MODE in this way:
Go to Game Center App Tab "Friends" click Setting at the end of the screen: SANDBOX and LOGGING MUST BE ON MODE
I hope that it works for everyone
You can use that, I create a Easy Game Center for iOS game center in github https://github.com/DaRkD0G/Easy-Game-Center-Swift
Message from France, Merry Christmas
Begin
(1) Add FrameWork GameKit.framework
(2) Create two files :
GKLocalPlayerHack.h
GKLocalPlayerHack.m
(3) In your Swift Bridging Header.h (Objectic-c import)
Next
}
Assuming that you've enabled Game Center in your app and also added a leaderboard in iTunes Connect then you need to authenticate your player before you can show GC. Also, be sure that you've created a test user in iTunes Connect that you can use to log in to Game Center when the prompt appears.
Your
MenuViewController
should authenticate the local player in viewDidLoad like so:After you've successfully authenticated then you should be able to present Game Center.
Note the line:
var localPlayer = getLocalPlayer() // see GKLocalPlayerHack.h
To get that to work you need to do a little hack to get GKLocalPlayer to instantiate correctly in Swift.
Create a new class in Objective-C and name the file GKLocalPlayerHack.h/m
In the header put:
In the implementation file put:
Be sure to add:
To your bridging header. Credit to @marmph for his answer in this question: Game Center not authenticating using Swift