本文介绍了在OSX上实现GameKit.framework,无法验证localPlayer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的OSX游戏中实现GameKit。不幸的是,我找不到很多关于如何做到这一点的信息;所有教程似乎都是iOS(虽然游戏中心可在iOS和OS X上使用)。

I'm attempting to implement GameKit in my OSX game. Unfortunately I can't find much information about how to do this; all tutorials seem to be iOS (though the documentation clearly states "Game Center is available on iOS and OS X").

一切都编译良好;当我尝试验证本地用户:

Everything is compiling fine; the problem comes when I try to authenticate the local user:

    [[GKLocalPlayer localPlayer] setAuthenticateHandler:^(id viewController, NSError *error) {
        if(error) {
          DLog(@"Error: %@",error);// This is always returning an error
        }
        else if(viewController) {
          // WHAT DO I DO HERE??
        }
      }];

我有2个问题:

,处理程序总是会收到一个错误:错误域= GKErrorDomain代码= 6无法完成请求的操作,因为本地播放器尚未通过身份验证。 UserInfo = 0x10103bc70 {NSLocalizedDescription =请求的操作无法完成,因为本地播放器尚未通过身份验证。}

First, the handler always gets an error: Error Domain=GKErrorDomain Code=6 "The requested operation could not be completed because local player has not been authenticated." UserInfo=0x10103bc70 {NSLocalizedDescription=The requested operation could not be completed because local player has not been authenticated.}.

在iPhone上,这段代码工作正常:没有错误,我只是提供viewController(这是登录屏幕) 。

On the iPhone, this code works fine: there's no error, and I simply present the viewController (which is the login screen).

推荐答案

很抱歉,我意识到我的答案差不多一年了,与其他仍然像我一样问这个问题的人相关。

I'm sorry, and I realize that my answer is almost a year late, but in case it may still be relevant for others who are still asking this question like myself. Ed Marty is mostly correct, but what I've discovered that works for me is this.

[[GKLocalPlayer localPlayer] setAuthenticateHandler:^(NSViewController < GKViewController >  viewController, NSError *error) {

          if(error) {
             NSLog(@"Error: %@",error);
          }
          else if(viewController) {
            GKDialogController *presenter = [GKDialogController sharedDialogController];
            presenter.parentWindow = myWindow;
            [presenter presentViewController:viewController];
         }
}];

主要区别是使用符合GKViewController而不是id的NSViewController DLog,但这不是太重要)。

The main difference is using NSViewController conforming to GKViewController instead of id.(Also, I used NSLog instead of DLog, but that isn't too important).

但我发现,这是完全无用的,它提出了登录对话框,之前甚至调用处理程序。

"I have found, however, that this is completely useless, and it presents the login dialog before it even calls the handler."

为确保其正常工作,请通过您的应用程序设置一个新的Game Center帐户。当您运行程序并加载窗口以供您登录时,即使您已有Apple ID,也可以按创建新的Apple ID。按钮可能不工作,所以如果是这样,打开游戏中心,然后按创建新的苹果ID。无论哪种方式,您的目标是创建一个沙盒游戏中心帐户,您可以在这里了解更多:

To make sure that it works, set up a new Game Center account through your app. When you run your program and it loads a window for you to sign in, press "Create New Apple ID" even if you already have an Apple ID. The button may not work, so if that's the case, open up Game Center and press "Create New Apple ID." Either way, your objective is to create a "Sandboxed" Game Center account, which you can learn more about here: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/TestingYourGameCenter-AwareGame/TestingYourGameCenter-AwareGame.html#//apple_ref/doc/uid/TP40008304-CH17-SW1

您可以判断account is Sandboxed如果在阅读条款和条件时,单词Sandbox出现在左上角的黄色横幅上。再次,我很抱歉我迟到,但希望这将清除所有未来的观众的主题。

You can tell if the account is Sandboxed if when you are reading the terms and conditions, the word "Sandbox" appears on a yellow banner in the top left. Once again, I'm sorry I'm late, but hopefully this clears the topic for all future viewers.

很抱歉,代码格式不正确。

P.S. I'm sorry that the code did not format properly.

这篇关于在OSX上实现GameKit.framework,无法验证localPlayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 23:44