Game Center not authenticating using Swift

≡放荡痞女 提交于 2019-11-27 22:31:45
marmph

This issue has been resolved by Apple - just call:

GKLocalPlayer.localPlayer()

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

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):

In an Objective-C header:

GKLocalPlayer *getLocalPlayer(void);

In an Objective-C implementation:

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

In your bridging header:

#import "ThatHeader.h"

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.

Even with Xcode 6 Beta 6, on a device using iOS 8 beta 5, making GKLocalPlayer.localPlayer() available, I was still getting the error:

"NSLocalizedDescription=The requested operation could not be completed because this application is not recognized by Game Centre"

The solution (discovered through Apple's Dev forum) was to go to "Settings" on the device, and then into "Game Centre" and enable "Sandbox" under the developer section.

You can use that, I create a simple class for iOS game center in github Easy Class Game Center Swift

https://github.com/DaRkD0G/Easy-Game-Center-Swift

Message from France, Merry Christmas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!