-1
안녕하세요, 즉시 내 리더 보드에 점수를 얻는 데 어려움이 있습니다. 연결의 모든 것이 좋습니다. 나는 이전에 성공적으로 리더 보드를했지만 목표는 c였습니다. 제가 빠진 신속한 버그가 있는지 궁금합니다. 새 점수를 제출할 때 오류가 발생하지 않습니다. 다음과 같이 gamecenterhelper 클래스를 만들어 게임 센터 전체를 수행합니다.스위프트 게임 센터 리더 보드 점수가 없음
감사합니다. 그래 내 아이디의 모든 올바른
스위프트 GameCenterHelper
import Foundation
import GameKit
class GameCenterHelperSwift: NSObject, GKGameCenterControllerDelegate {
var leaderboardIdentifier: String? = nil
var gameCenterEnabled: Bool = false
var myViewController: UIViewController!
init(VC:UIViewController){
myViewController = VC
}
func openLeaderBoard(id: String) {
var gameCenter = GKGameCenterViewController()
gameCenter.gameCenterDelegate = self
gameCenter.leaderboardIdentifier = id
self.myViewController.presentViewController(gameCenter, animated: true, completion: nil)
}
func authenticateLocalPlayer()
{
var localPlayer = getLocalPlayer() // see GKLocalPlayerHack.h
localPlayer.authenticateHandler =
{ (viewController : UIViewController!, error : NSError!) -> Void in
if viewController != nil
{
self.myViewController.presentViewController(viewController, animated:true, completion: nil)
}
else
{
if localPlayer.authenticated
{
self.gameCenterEnabled = true
localPlayer.loadDefaultLeaderboardIdentifierWithCompletionHandler
{ (leaderboardIdentifier, error) -> Void in
if error != nil
{
print("error")
}
else
{
self.leaderboardIdentifier = leaderboardIdentifier
println("\(self.leaderboardIdentifier)")
}
}
}
else
{
println("not able to authenticate fail")
self.gameCenterEnabled = false
if (error != nil)
{
println("\(error.description)")
}
else
{
println( "error is nil")
}
}
}
}
}
func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController!) {
gameCenterViewController.dismissViewControllerAnimated(true, completion: nil)
}
func saveHighscore(id: String, Score: Float){
if GKLocalPlayer.localPlayer().authenticated {
var scoreReporter = GKScore(leaderboardIdentifier: id)
scoreReporter.value = Int64(Score);
var scores = [scoreReporter]
GKScore.reportScores(scores, withCompletionHandler: { (error : NSError!) -> Void in
println("reporting")
if error != nil {
println("error")
println("\(error.localizedDescription)")
}else{
println("nice score!")
}
})
}
}
}
목표 C 인증 해킹 (잘, 다시 환영받을 작품) 리더 보드 ID의
// GKLocalPlayerHack.h
// Issue with GameKit and Swift
// http://stackoverflow.com/questions/24045244/game-center-not-authenticating-using- swift
#import <GameKit/GameKit.h>
@interface GKLocalPlayerHack : NSObject
GKLocalPlayer *getLocalPlayer(void);
@end
// GKLocalPlayerHack.m
// Issue with GameKit and Swift
// http://stackoverflow.com/questions/24045244/game-center-not-authenticating-using-swift
#import "GKLocalPlayerHack.h"
@implementation GKLocalPlayerHack
GKLocalPlayer *getLocalPlayer(void)
{
return [GKLocalPlayer localPlayer];
}
@end