2015-12-22 10 views
5

現在、Game CenterはiOSターゲットで動作していますが、tvOSターゲットでは動作していません。tvOSのゲームセンターが表示されない

私はすでにリーダーボードの画像を追加し、ここでXcodeで識別子を配置した:

enter image description here

をこれは私がリーダーボードを持参し、プレイヤーを開始するために使用しているクラスです。それはGameKitHelper.swiftと呼ばれています:

import UIKit 
import Foundation 
import GameKit 

let PresentAuthenticationViewController = "PresentAuthenticationViewController" 

class GameKitHelper: NSObject { 

    static let sharedInstance = GameKitHelper() 


    var authenticationViewController: UIViewController? 
    var gameCenterEnabled = false 

    func authenticateLocalPlayer() { 

    //1 
    let localPlayer = GKLocalPlayer() 
    localPlayer.authenticateHandler = {(viewController, error) in 

     if viewController != nil { 
      //2 
      self.authenticationViewController = viewController 

       NSNotificationCenter.defaultCenter().postNotificationName(PresentAuthenticationViewController, object: self) 
     } 
    else if error == nil { 
      //3 
      self.gameCenterEnabled = true 
     } 
    } 

} 

func reportAchievements(achievements: [GKAchievement], errorHandler: ((NSError?)->Void)? = nil) { 
    guard gameCenterEnabled else { 
     return 
    } 

    GKAchievement.reportAchievements(achievements, withCompletionHandler: errorHandler) 
} 

func showGKGameCenterViewController(viewController: UIViewController) { 
    guard gameCenterEnabled else { 
     return 
    } 

    //1 
    let gameCenterViewController = GKGameCenterViewController() 

    //2 
    gameCenterViewController.gameCenterDelegate = self 

    //3 
    viewController.presentViewController(gameCenterViewController, animated: true, completion: nil) 
} 

    func saveHighScore(identifier: String, score: Int) { 

    if (GKLocalPlayer.localPlayer().authenticated) { 

     let scoreReporter = GKScore(leaderboardIdentifier: identifier) 
     scoreReporter.value = Int64(score) 

     let scoreArray:[GKScore] = [scoreReporter] 

     GKScore.reportScores(scoreArray, withCompletionHandler: { 

      error -> Void in 

      if (error != nil) { 

       print("error") 
      } 
      else { 

       print("Posted score of \(score)") 
      } 
     }) 
    } 
    } 
} 

extension GameKitHelper: GKGameCenterControllerDelegate { 
    func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController) { 
    gameCenterViewController.dismissViewControllerAnimated(true, completion: nil) 
} 
} 

NavigationControllerクラス:

override func viewDidLoad() { 
    super.viewDidLoad() 

    NSNotificationCenter.defaultCenter().addObserver(self, 
              selector: Selector("showAuthenticationViewController"), 
               name: PresentAuthenticationViewController, 
               object: nil) 
    GameKitHelper.sharedInstance.authenticateLocalPlayer() 
} 

func showAuthenticationViewController() { 
    let gameKitHelper = GameKitHelper.sharedInstance 

    if let authenticationViewController = gameKitHelper.authenticationViewController { 
     topViewController?.presentViewController(authenticationViewController, 
               animated: true, 
               completion: nil) 
    } 
    } 


    deinit { 
     NSNotificationCenter.defaultCenter().removeObserver(self) 
    } 
+0

少し詳しい情報を追加できますか?ユーザーの初期化が成功し、gameCenterEnabledがtrueであることを確認しましたか? – Stefan

+0

@Stefan 'func authenticateLocalPlayer()'をチェックしてください。また、私はいくつかのGame Centerコードを実行する別のクラスを持っていますが、私が投稿したクラスはメインクラスであると確信しています。私が言ったように、これはiOSでうまく動作します。私は高いスコアを投稿することさえできますが、tvOSではできません。 – Paul

答えて

0

は、アプリの資産カタログに "Apple TVのダッシュボードイメージ" を持っていることを確認してください。ダッシュボードのアートワークは923x150の透明度を持つ必要があり、ユーザーが選択できないため、レイヤーを作成する必要はありません。

tvOS Human Interface Guidelinesダッシュボードのアートワークはオプションですが、私の経験ではGKGameCenterViewControllerは持っていないと表示されません。

関連する問題