在 Swift 中调用成就屏幕

Calling achievement screen in Swift

我在调用游戏中心的成就屏幕时遇到一些极度困难。我已经在 iTunes connect 中设置了成就,如果我先通过排行榜访问成就屏幕,它会弹出。然而;我希望能够按下特定的成就按钮并直接转到成就屏幕。任何人都可以帮忙吗?我在互联网上搜索了高低(and read through all of the documentation)。我找到了许多用于实现排行榜的资源,但用于实现 swift 成就的资源并不多。我的代码如下。对我的最后两个功能有什么建议吗?

override func viewDidLoad() {
    super.viewDidLoad()

    login()

}

func login() {
    println("Game Center Login Called")
    let localPlayer = GKLocalPlayer.localPlayer()

    // Handle the authentication
    localPlayer.authenticateHandler = {(Home: UIViewController!, error: NSError!) -> Void in
        if Home != nil {
            println("Authentication is being processed.")
            self.presentViewController(Home, animated: true, completion: nil)

        } else {
            println("Player has been successfully authenticated.")
        }
    }

}

func showLeaderboard() {


    let gkScore = GKScore(leaderboardIdentifier: "high_Score_Leader_Board")
    gkScore.value = Int64(highscore)
    GKScore.reportScores([gkScore], withCompletionHandler: ( { (error: NSError!) -> Void in
        if (error != nil) {
            // handle error
            println("Error: " + error.localizedDescription);
        } else {
            println("Score reported: \(gkScore.value)")
        }
    }))


    var gcViewController: GKGameCenterViewController = GKGameCenterViewController()
    gcViewController.gameCenterDelegate = self

    gcViewController.viewState = GKGameCenterViewControllerState.Leaderboards

    gcViewController.leaderboardIdentifier = "high_Score_Leader_Board"
    self.showViewController(gcViewController, sender: self)
    self.presentViewController(gcViewController, animated: true, completion: nil)
}





@IBAction func gameCenterButtoPressed(sender: AnyObject) {
    showLeaderboard()
}



func gameCenterViewControllerDidFinish(gcViewController: GKGameCenterViewController!)
{
    self.dismissViewControllerAnimated(true, completion: nil)
}

func showAchievements() {
    // show Achievements screen
}


@IBAction func achievementButtonPressed(sender: AnyObject) {

    // Call show achievements function when button pressed
}

而不是:

gcViewController.viewState = GKGameCenterViewControllerState.Leaderboards

我想你会想要的是:

gcViewController.viewState = GKGameCenterViewControllerState.Achievements

我找到了这个信息 in this related tutorial