斯威夫特游戏中心领导委员会显示没有分数

时间:2015-01-15 01:02:16

标签: swift game-center game-center-leaderboard

嗨,我很难在swift中获得分数。连接中的一切都很好。我之前已成功完成了排行榜,但目标是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认证hack(工作得很好,欢迎回来)

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

1 个答案:

答案 0 :(得分:0)

排行榜ID的格式已更改。

而不是&#34; come.company.id&#34;

现在只是

&#34; ID&#34;