-1

嗨,我无法迅速将分数列入我的排行榜。连接中的一切都很好。我以前成功地完成了排行榜,但在目标 c 中。我想知道是否有我遗漏的快速错误。提交新分数时我没有收到任何错误。我创建了一个 gamecenterhelper 类,我通过它完成所有游戏中心,如下所示:

谢谢!!是的,我的身份证都是正确的

Swift 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!")

        }

    })
    }
}

}

Objective C 身份验证黑客(工作得很好,得到欢迎回来)

//  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
4

1 回答 1

0

排行榜 ID 的格式已更改。

而不是“come.company.id”

现在只是

“ID”

于 2015-01-15T02:13:48.047 回答