func authenticateLocalPlayer() {
var localPlayer = GKLocalPlayer.localPlayer()
localPlayer.authenticateHandler = {(viewController : UIViewController!, error : NSError!) -> Void in
if viewController != nil {
self.presentViewController(viewController, animated: true, completion: nil)
}
else {
if localPlayer.authenticated {
self.gameCenterEnabled = true
localPlayer.loadDefaultLeaderboardIdentifierWithCompletionHandler({ (leaderboardIdentifier : String!, error : NSError!) -> Void in
if error != nil {
println(error.localizedDescription)
} else {
self.leaderboardIdentifier = leaderboardIdentifier
***above is your Game Center id***
}
})
} else {
self.gameCenterEnabled = false
}
}
}
}
在上面的代碼中有self.leaderboardIdentifier是遊戲中心ID
太感謝你了。但它不起作用。 – HeyYo
處於「self.leaderboardIdentifier = leaderboardIdentifier」行上 – HeyYo
致命錯誤:意外地發現零,同時展開可選值 – HeyYo