Displaying Leaderboards to Players
Problem
You want to display leaderboards to your app users using a graphical user interface.
Solution
Use the GKLeaderboardViewController class as shown in
the Discussion section.
Discussion
Game Center can construct built-in leaderboard screens for your games. Doing this is a piece of cake for Game Center. All you have to do is build an iOS application that makes use of view controllers. This is outside the scope of this book, but is thoroughly explained in iOS 4 Programming Cookbook. For the remainder of this section, I assume you have created an application with one view controller inside a navigation controller.
To have Game Center construct a leaderboard screen for your iOS app, follow these steps:
Make sure that you have a view controller in your application (see iOS 4 Programming Cookbook). Also make sure that your view controller conforms to the
GKLeaderboardViewControllerDelegateprotocol.Authenticate the local player (see Authenticating the Local Player in Game Center).
Allocate and instantiate an object of type
GKLeaderboardViewControllerand present it to the player using thepresentModalViewController:animated:instance method of your view controller.Implement the
leaderboardViewControllerDidFinish:delegate method of theGKLeaderboardViewControllerDelegateprotocol in your view controller.In the implementation of the
leaderboardViewControllerDidFinish:delegate method, dismiss your leaderboard view controller using the view controller’s ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access