Swift - Integrate GameCenter to use leaderboards

别说谁变了你拦得住时间么 提交于 2019-12-05 10:04:44

Your specific issue has nothing to do with Game Center and is happening because you have the line var localPlayer : GKLocalPlayer!.

You're declaring an implicitly unwrapped optional and then using it right away. It's value is nil in the subsequent line when you try to set localPlayer.authenticateHandler.

Instead you should instantiate GKLocalPlayer like so:

var localPlayer = GKLocalPlayer()

Note that there are currently issues with Game Center and Swift. Your code is going to work but localPlayer.authenticated never gets set to true. This issue is tracked here:

http://www.openradar.me/17825348

Credit to: http://www.stuarticus.net/blog/2014/7/game-center-authentication-and-swift for filing the radar ticket.

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

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