title: Game Center Not Properly Working. Swift, Sprite Kit
body: <p>I recently tried to add Game Center to my Sprite Kit Game, but it's not working properly. </p>
  
  <p>When the game starts in the simulator, the Game Center login page does show up. When I start the game on my phone it does not. Can someone tell me what I am doing wrong.</p>
  
  <pre><code>//GameViewController.Swift
  import GameKit
  
  class GameViewController: UIViewController, ADBannerViewDelegate, GKGameCenterControllerDelegate {
  
  var bannerView:ADBannerView?
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      // Presenting scene without using GameScene.sks
      let skView = view as! SKView
      let myScene = GameScene(size: skView.frame.size)
      myScene.scaleMode = .ResizeFill
  
      skView.presentScene(myScene)
      authenticateLocalPlayer()
  
  }
  
  //initiate gamecenter
  func authenticateLocalPlayer(){
  
      var localPlayer = GKLocalPlayer.localPlayer()
  
      localPlayer.authenticateHandler = {(viewController, error) -&gt; Void in
  
          if (viewController != nil) {
              self.presentViewController(viewController, animated: true, completion: nil)
          }
  
          else {
              println((GKLocalPlayer.localPlayer().authenticated))
          }
      }
  
  }
  
  func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController!)
  {
      gameCenterViewController.dismissViewControllerAnimated(true, completion: nil)
  }
  
  
  
  //GameScene.Swift
  import GameKit
  
  class GameScene: SKScene, SKPhysicsContactDelegate{
  var playerScore = 0
  func playerScoreUpdate() {
      playerScorelabel.text = "\(playerScore)"
  }
  
  func saveHighScore(high:Int) {
      NSUserDefaults.standardUserDefaults().setInteger(high, forKey: "highscore")
      //check if user is signed in
      if GKLocalPlayer.localPlayer().authenticated {
  
          var scoreReporter = GKScore(leaderboardIdentifier: "TF1G002ID") //leaderboard id here
  
          scoreReporter.value = Int64(playerScore) //score variable here (same as above)
  
          var scoreArray: [GKScore] = [scoreReporter]
  
          GKScore.reportScores(scoreArray, withCompletionHandler: {(error : NSError!) -&gt; Void in
              if error != nil {
                  println("error")
              }
          })
  
      }
  }
  
  
  
  //GameOver.Swift
  import GameKit
  
  class GameOverScene: SKScene, GKGameCenterControllerDelegate {
  
  //shows leaderboard screen
  func showLeader() {
      var vc = self.view?.window?.rootViewController
      var gc = GKGameCenterViewController()
      gc.gameCenterDelegate = self
      vc?.presentViewController(gc, animated: true, completion: nil)
  }
  
  // Press Finger
  override func touchesBegan(touches: Set&lt;NSObject&gt;, withEvent event: UIEvent) {
      for touch: AnyObject in touches {
          let location = touch.locationInNode(self)
          let node = self.nodeAtPoint(location)
  
          if node.name == "replay" {
              playSound(sound)
          }
  
          if node.name == "leaderboard" {
              showLeader()
          } 
      }
  }
  
  //hides leaderboard screen
  func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController!)
  {
      gameCenterViewController.dismissViewControllerAnimated(true, completion: nil)
  
  }
  </code></pre>