Game Development Reference
because of the multitasking nature introduced with iOS 4.0. Essentially, your
game must be prepared to handle the local player logging out and some other
player signing in at any time during game play. Typically, you should end the
current game session and return to a safe place—for example, the main menu.
But you should consider saving the current state of the game for each local
player as they sign out so that when they sign back in, the game continues ex-
actly where that player left the game.
The actual authentication is performed by the authenticateLocalPlayer meth-
od, in Listing 14-5 .
if (isGameCenterAvailable == NO)
GKLocalPlayer* localPlayer = GKLocalPlayer.localPlayer;
if (localPlayer.authenticated == NO)
[localPlayer authenticateWithCompletionHandler: ←
At first glance, that's relatively straightforward. The localPlayer object is ob-
tained, and if it's not authenticated, the authenticateWithCompletionHand-
ler method is called. And the NSError object returned by the method is set to the
lastError and . . . hey, wait a second. That's all part of the method's parameter?
Yes. These inline methods are called block objects , which I introduced at the end of
the next section as a refresher. For now, just know that the block object is a C-style