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

Retrieving the Local Player’s Information

Problem

You have authenticated the local player, but you need to get her alias and other information.

Solution

Use different properties available to the GKLocalPlayer class, such as the alias property, as demonstrated in the Discussion section.

Discussion

The GKPlayer object represents a player in Game Center. Each player possesses a few very important properties:

playerID

Each player in Game Center has an identifier. This identifier should not be displayed to the player. Instead, the player alias is what the player is interested in seeing in leaderboards, etc. In many Game Center methods, we will first be able to retrieve players’ IDs and use them to load other information for the player, such as her scores in a specific leaderboard. In other words, player IDs are important only when working with Game Center APIs.

alias

The alias that the player sets for herself during the registration process in Game Center. You can display this alias to the player if you wish.

isFriend

This property returns a value of type BOOL, allowing you to determine whether the player is the friend of the currently authenticated local player.

This is a property of the GKPlayer class only. Although the GKLocalPlayer class subclasses GKPlayer, the isFriend property cannot be accessed in the GKLocalPlayer class.

Now let’s go ahead and demonstrate this with example code. In this code, what I want to demonstrate can be separated into two pieces of code expressed in block objects. ...

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