Game Center 未使用 Swift 进行身份验证 [英] Game Center not authenticating using Swift

查看:19
本文介绍了Game Center 未使用 Swift 进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 swift 对本地播放器进行身份验证,但每次我收到 .authenticated 属性的错误值时.这是我正在使用的代码,它在应用程序启动时由主视图控制器调用.

I'm trying to authenticate the local player using swift, but every time I get a false value for the .authenticated property. Here is the code I'm using, it is called by the main view controller when the app starts.

func authenticateLocalPlayer(){
  var localPlayer = GKLocalPlayer()
  localPlayer.authenticateHandler = {(viewController, error) -> Void in
    if viewController {
      self.presentViewController(viewController, animated: true, completion: nil)
    }else{
      println((GKLocalPlayer().authenticated))
    }
  }
}

它可以很好地显示登录视图,但是当我输入测试帐户登录时,它只会返回 GKLocalPlayer().authenticated 作为 false.iTunes Connect 中的包标识符和 info.plist 完全相同,版本和应用程序名称也是如此.在 iTunes Connect 和 Xcode 中,Game Center 的所有功能都已启用,但我感觉这不是编码错误,而是应用程序记录中某处的设置错误,但我终生无法找到其中的位置.

It brings up the log in view just fine, but when I enter a test account login, it just returns the GKLocalPlayer().authenticatedas false. The bundle identifier in iTunes Connect and the info.plist are exactly the same, as is the version and the app name. Everything is enabled for Game Center on iTunes Connect and in Xcode, but I have a feeling it's not a coding error, it's a setup error in the app record somewhere but I can't for the life of me find where.

进一步修改后,我收到此错误:

After further tinkering, I'm getting this error:

Error Domain=GKErrorDomain Code=15 请求的操作无法完成,因为游戏中心无法识别此应用程序."UserInfo=0x17006b300 {NSLocalizedDescription=请求的操作无法完成,因为游戏中心无法识别此应用程序.}

Error Domain=GKErrorDomain Code=15 "The requested operation could not be completed because this application is not recognized by Game Center." UserInfo=0x17006b300 {NSLocalizedDescription=The requested operation could not be completed because this application is not recognized by Game Center.}

我不知道为什么会这样,包 ID、名称和版本都匹配...

I have no idea why this is the case, the bundle ID, name and versions all match...

任何帮助将不胜感激.

推荐答案

Apple 已解决此问题 - 只需致电:

This issue has been resolved by Apple - just call:

GKLocalPlayer.localPlayer()

以前,问题是 GKLocalPlayer() 不返回 GKLocalPlayer 单例,而是返回一个新的 GKLocalPlayer 实例.

Previously, the issue was that GKLocalPlayer() does not return the GKLocalPlayer singleton, but instead returns a new GKLocalPlayer instance.

如果您使用的是 Xcode 6 BETA,您可以添加一个 C 函数或 Objective-C 方法来返回真正的 GKLocalPlayer 单例,然后在 Swift 中使用它.这是我的解决方法的要点(使用错误的命名约定):

If you were on the Xcode 6 BETA, you could add a C function or Objective-C method that returns the real GKLocalPlayer singleton, then use this in Swift. This is the gist of my workaround (with bad naming conventions):

在 Objective-C 标头中:

In an Objective-C header:

GKLocalPlayer *getLocalPlayer(void);

在 Objective-C 实现中:

In an Objective-C implementation:

GKLocalPlayer *getLocalPlayer(void) {
    return [GKLocalPlayer localPlayer];
}

在您的桥接头中:

#import "ThatHeader.h"

那么当你需要在 Swift 中访问 GKLocalPlayer 单例时,你可以使用 getLocalPlayer() 而不是 GKLocalPlayer().将其保留在 GKLocalPlayer 类别的方法中可能是一个更好的主意.

Then whenever you need to access the GKLocalPlayer singleton in Swift, you can just use getLocalPlayer() instead of GKLocalPlayer(). It's probably a better idea to stick that in an method of a GKLocalPlayer category.

但是,如上所述,这不再是必要的.

However, this is no longer necessary as detailed above.

这篇关于Game Center 未使用 Swift 进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆