Reputation: 1619
I'd like to integrate Game Center with my game, and I've already enabled it. I've found some code for authenticating the player (http://www.codeinjection.me/blog/2014/7/game-center-authentication-and-swift), but I don't know where to put it. And after authenticating the player, how should I go about implementing leaderboards and achievements? And displaying them in the game? Thanks in advance?
Edit: Also, the code in the link as well as many other authentication code samples I've seen for Swift use self.delegate? often, but when I try pasting the code into my program, it tells me that AppDelegate doesn't have a member named delegate. Does anyone know how to fix this?
Upvotes: 0
Views: 834
Reputation: 11766
Apple provides some great guides about Game Center, basically you will have to:
Set up your leaderboards, achievements etc. in the iTunes Connect website: Game Center Configuration Guide for iTunes Connect
Integrate the Game Center in your app: Game Center Programming Guide
The player authentication is usually done in the didFinishLaunchingWithOptions:
of the app delegate (Apple sample code here). But the guides I mentioned explain everything, the code examples are in Objective-C but the APIs are the same in Swift, you just need to change the syntax for example:
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
Becomes
let localPlayer = GKLocalPlayer()
It's some homework to do, but that's the price if you want to use Swift ;)
Upvotes: 2