title: Game Center login
body: <p>In my game players need to log in with Apples Game Center. If they are a new player to the game, they have to be signed in to Game Center first because I use the playerID as part of the data used to setup a new user account.</p>
  
  <p>I have a GameCenter class, which I use to sign the player in, or prompt them to sign in if they are not already, here's the main code.</p>
  
  <pre><code>-(void) setup
  {
      gameCenterAuthenticationComplete = NO;
  
      if (!isGameCenterAPIAvailable()) {
          // Game Center is not available.
          NSLog(@"Game Center is not available.");
      } else {
          NSLog(@"Game Center is available.");
  
              __weak typeof(self) weakSelf = self; // removes retain cycle error
  
              GKLocalPlayer *localPlayer =  [GKLocalPlayer localPlayer]; // localPlayer is the public GKLocalPlayer
  
          __weak GKLocalPlayer *weakPlayer = localPlayer; // removes retain cycle error
  
              weakPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
              {
                  if (viewController != nil)
                  {
                      [weakSelf showAuthenticationDialogWhenReasonable:viewController];
                  }
                  else if (weakPlayer.isAuthenticated)
                  {
                      [weakSelf authenticatedPlayer:weakPlayer];
                  }
                  else
                  {
                      [weakSelf disableGameCenter];
                  }
              };
          }
  
      }
  
      -(void)showAuthenticationDialogWhenReasonable:(UIViewController *)controller
      {
          [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:controller animated:YES completion:nil];
      }
  
      -(void)authenticatedPlayer:(GKLocalPlayer *)player
      {
          NSLog(@"%@,%@,%@",player.playerID,player.displayName, player.alias);
  
          localPlayer = player;
  
          gameCenterAuthenticationComplete = YES;       
  
      }
  
      -(void)disableGameCenter
      {
  
      }
  </code></pre>
  
  <p>And that works fine. But I have 2 issues.</p>
  
  <p>1) As I said if the player is new, then they HAVE to be signed in to Game Center before new user registration can go ahead. This new registration is in another class. So how do I get the other class to listen to the GameCenter's variable gameCenterAuthenticationComplete = YES ? I read elsewhere that I can use a delegate, but does that work across objects? would a notification be better across objects?</p>
  
  <p>2) And more importantly, what happens if the player closes the modal to sign in to GameCenter, where is the call back/block for when the modal is closed? so I can prompt them to sign in again or at least put up a msg on screen?</p>