游戏中心不在模拟器中连接

时间:2015-08-05 13:44:55

标签: ios swift ios-simulator game-center

我创建了一个使用Game Center和的应用 这是我添加到文件中的代码:

func authenticateLocalPlayer(){

    var localPlayer = GKLocalPlayer.localPlayer()

    localPlayer.authenticateHandler = {(viewController, error) -> Void in

        if (viewController != nil) {
            self.presentViewController(viewController, animated: true, completion: nil)

        }

        else {
            println((GKLocalPlayer.localPlayer().authenticated))
            println(error)
        }
    }

}

func showLeader() {
    var vc = self.view?.window?.rootViewController
    var gc = GKGameCenterViewController()
    gc.gameCenterDelegate = self
    vc?.presentViewController(gc, animated: true, completion: nil)
}

//hides leaderboard screen
func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController!)
{
    gameCenterViewController.dismissViewControllerAnimated(true, completion: nil)

}
func saveHighscore(score:Int) {

    //check if user is signed in
    if GKLocalPlayer.localPlayer().authenticated {

        var scoreReporter = GKScore(leaderboardIdentifier: "countrymasterlbid20151993") //leaderboard id here

        scoreReporter.value = Int64(score) //score variable here (same as above)

        var scoreArray: [GKScore] = [scoreReporter]

        GKScore.reportScores(scoreArray, withCompletionHandler: {(error : NSError!) -> Void in
            if error != nil {
                println("error")
            }
        })

    }

}

@IBAction func gc(sender: AnyObject) {
    saveHighscore(score)
    showLeader()
}

ViewDidLoad基金中我添加了这段代码:

authenticateLocalPlayer()

当我运行simulator时,它没有显示connection viewerror消息:

  

错误域= GKErrorDomain代码= 2“请求的操作已经执行   用户取消或禁用。“UserInfo = 0x7fcee382af30   {NSLocalizedDescription =请求的操作已被取消或   被用户禁用。}

0 个答案:

没有答案