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
GKLeaderboardViewControllerDelegate
protocol.Authenticate the local player (see Authenticating the Local Player in Game Center).
Allocate and instantiate an object of type
GKLeaderboardViewController
and present it to the player using thepresentModalViewController:animated:
instance method of your view controller.Implement the
leaderboardViewControllerDidFinish:
delegate method of theGKLeaderboardViewControllerDelegate
protocol in your view controller.In the implementation of the
leaderboardViewControllerDidFinish:
delegate method, dismiss your leaderboard view controller using the view controller’s ...
Get Writing Game Center Apps in iOS now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.