Skip to Main Content
Writing Game Center Apps in iOS
book

Writing Game Center Apps in iOS

by Vandad Nahavandipoor
April 2011
Intermediate to advanced content levelIntermediate to advanced
80 pages
2h
English
O'Reilly Media, Inc.
Content preview from Writing Game Center Apps in iOS

Displaying Achievements to Players

Problem

You need to display the achievements that the local player has received or is in the progress of receiving, using a graphical user interface.

Solution

Use the GKAchievementViewController class.

Discussion

Game Center can construct built-in achievements screens for your games. All you have to do is to build an iOS application that makes use of view controllers, covered 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.

In order to have Game Center construct an achievement screen for your iOS app, follow these steps:

  1. Make sure that you have a view controller in your application (see iOS 4 Programming Cookbook). Also make sure your view controller conforms to the GKAchievementViewControllerDelegate protocol.

  2. Authenticate the local player (see Authenticating the Local Player in Game Center).

  3. Allocate and instantiate an object of type GKAchievementViewController and present it to the player using the presentModalViewController:animated: instance method of your view controller.

  4. Implement the achievementViewControllerDidFinish: delegate method of the GKAchievementViewControllerDelegate protocol in your view controller.

  5. In the implementation of the achievementViewControllerDidFinish: delegate method, dismiss your achievement view controller using the view controller’s dismissModalViewControllerAnimated: instance method.

Instances of the GKAchievementViewController ...

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.
Start your free trial

You might also like

Beginning ARKit for iPhone and iPad: Augmented Reality App Development for iOS

Beginning ARKit for iPhone and iPad: Augmented Reality App Development for iOS

Wallace Wang

Publisher Resources

ISBN: 9781449307950Supplemental ContentErrata Page