Game Development Reference
In-Depth Information
that's sent through NSNotificationCenter . You register a selector to receive the
message, as shown in Listing 14-4 .
Listing 14-4 . Registering for Local Player Authentication Changes
-(void) registerForLocalPlayerAuthChange
{
if (isGameCenterAvailable == NO)
return;
NSNotificationCenter* nc = NSNotificationCenter.defaultCenter;
[nc addObserver:self
selector:@selector(onLocalPlayerAuthenticationChanged)
name:GKPlayerAuthenticationDidChangeNotificationName
object:nil];
}
As you can see, isGameCenterAvailable is used here to skip the rest of the
method in case Game Center isn't available. You'll notice other methods doing the
same thing, and I'll refrain from repeating this in the topic's code.
The actual method being called by NSNotificationCenter simply forwards the
message to the delegate, but only if the delegate implements the onLocalPlayer-
AuthenticationChanged message. Because the GameKitHelper delegate
methods are marked as @optional , this precaution is necessary to avoid crashes.
-(void) onLocalPlayerAuthenticationChanged
{
if ([delegate respondsToSelector:@selector(onLocalPlayerAuthenticationChanged)])
{
[delegate onLocalPlayerAuthenticationChanged];
}
}
Note The local player's signed-in status may actually change while the game is
in the background and the user runs the Game Center app and signs out. That's
 
 
Search Nedrilad ::




Custom Search