且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Game Center 未使用 Swift 进行身份验证

更新时间:2023-12-03 09:07:34

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.