Как открыть GameCenter в tvOS

Как я могу открыть таблицу лидеров игрового центра в tvOS? Я использовал этот код для своих игр для iPhone, 'leaderboardIdentifier' недоступен в tvOS.

Я планировал использовать ту же таблицу лидеров на AppleTV (это будет та же игра).

Большое спасибо за помощь, Стефан

    @IBAction func handleGameCenter(sender: UIButton) {
        let gcViewController = GKGameCenterViewController()
        gcViewController.viewState = GKGameCenterViewControllerState.Leaderboards
        gcViewController.leaderboardIdentifier = gamePrefix + "Leaderboard"
        gcViewController.gameCenterDelegate = self

        // Show leaderboard
        self.presentViewController(gcViewController, animated: true, completion: nil)
    }

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

person Stefan    schedule 24.09.2015    source источник


Ответы (3)


У меня также была проблема с экраном «Нет доступных данных», но, наконец, я решил ее. Это сработало для меня, чтобы открыть таблицу лидеров GameCenter на tvOS:

  1. откройте Assets.xcassets (тот же файл, в котором вы установили значок/экран запуска приложения)
  2. щелкните правой кнопкой мыши на панели с appicon/launchsreen и выберите Game Center -> New Apple TV Leaderboard.
  3. добавить графику для новой таблицы лидеров
  4. пока таблица лидеров выбрана в файле ресурсов на правой боковой панели, найдите поле «Идентификатор» и введите туда идентификатор вашей таблицы лидеров.
  5. используйте этот код, чтобы открыть таблицу лидеров:

    GKGameCenterViewController *gcViewController = [[GKGameCenterViewController alloc] init];
    gcViewController.gameCenterDelegate = self;
    [self presentViewController:gcViewController animated:YES completion:nil];
    
person Leszek Szary    schedule 20.10.2015
comment
Спасибо, что поделились этим решением! - person Reinaldo; 23.10.2015
comment
Идеальный ответ :) - person Siddharth; 08.09.2016

Просто это, кажется, работает:

GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil)
{
    gameCenterController.gameCenterDelegate = self;
    [self presentViewController: gameCenterController animated: YES completion:nil];
}
person Gavin Thornton    schedule 07.10.2015

.viewState и .leaderboardIdentifier недоступны в tvOS, поэтому вы можете открыть контроллер GC с помощью этого кода, но на странице будет указано «Нет доступных данных».

person Frank Eno    schedule 10.10.2015