ios - 使用 Swift 设置游戏中心?

标签 ios swift ios8 xcode6

<分区>

我对 Swift 和 iOS 编程还很陌生,我想知道如何设置 Game Center 排行榜、将玩家分数添加到排行榜并使用 Swift 更新玩家分数。

最佳答案

如果你谷歌如何设置游戏中心,你应该会找到一些对你有帮助的教程,它们与 iOS 8 有点过时,所以下面是一些不太容易翻译的部分。

验证玩家

let lp = GKLocalPlayer.localPlayer()
if lp.authenticated == false {
    lp.authenticateHandler() { (vc, error) -> Void in
        println(error)
    }
}

将分数添加到排行榜

leaderboardName = "My first game"
let scoreObj = GKScore(leaderboardIdentifier: leadeboardName)
scoreObj.context = 0
scoreObj.value = score
GKScore.reportScores([scoreObj], withCompletionHandler: {(error) -> Void in
    let alert = UIAlertView(title: "Success", 
                          message: "Score updated", 
                         delegate: self, 
                cancelButtonTitle: "Ok")
    alert.show()
})

关于ios - 使用 Swift 设置游戏中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25566083/

相关文章:

xcode - Swift - 如何让 NSSharingServicePicker 在特定按钮中弹出?

ios8 - 如何在横向模式下使用 Touch ID?

swift - iAd (ADBannerView) 工作,但在 Swift 中有奇怪的系统输出

iPad 的 iOS8 自动布局旋转似乎无法正确调整 collectionView 的大小

ios - 如何检测 UIButton 的触摸结束事件?

ios - 使图像适合iOS中的按钮

ios - notnoop Java-apns套接字已关闭

ios - 尝试使用 Application Loader 上传应用程序时出现错误 ITMS-9000

ios - 实现从 SwiftUI 到 UIViews 的填充

ios - FireBase - 维护/保证数据一致性