2015-01-15 158 views
-1

嗨我很難在我的排行榜上迅速獲得分數。連接的一切都很好。我之前成功地完成了一個排行榜,但是在客觀的情況下。我想知道是否有一個我缺少的快捷錯誤。提交新分數時我沒有錯誤。我創建了一個gamecenterhelper類,我可以完成所有遊戲中心,如下所示:迅捷遊戲中心排行榜顯示得分

Thanks! 和是我的id是正確的

斯威夫特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 

回答

0

格式已經改變。

而是 「come.company.id」

現在它只是

「ID」

相關問題